Skip to content

Commit

Permalink
Added: Update all mod pages upon adding collection.
Browse files Browse the repository at this point in the history
I think I'll change this to update at download time though.
This makes adding collections a bit too slow.
  • Loading branch information
Sewer56 committed Feb 27, 2025
1 parent b067059 commit 3f83845
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public partial class NexusModsLibrary
var collectionEntityId = UpdateCollectionInfo(db, tx, slug, collectionRevisionInfo.Collection);
var collectionRevisionEntityId = UpdateRevisionInfo(db, tx, revisionNumber, collectionEntityId, collectionRevisionInfo);

var resolvedEntitiesLookup = ResolveModFiles(db, tx, collectionRoot, gameIds, collectionRevisionInfo);
var resolvedEntitiesLookup = await ResolveModFiles(db, tx, collectionRoot, gameIds, collectionRevisionInfo);
UpdateFiles(db, tx, collectionRevisionEntityId, collectionRevisionInfo, collectionRoot, gameIds, resolvedEntitiesLookup);

var results = await tx.Commit();
Expand Down Expand Up @@ -207,7 +207,7 @@ private static List<ModAndDownload> GatherDownloads(CollectionDownload.ReadOnly[
return list;
}

private static ResolvedEntitiesLookup ResolveModFiles(
private async Task<ResolvedEntitiesLookup> ResolveModFiles(
IDb db,
ITransaction tx,
CollectionRoot collectionRoot,
Expand All @@ -232,6 +232,7 @@ private static ResolvedEntitiesLookup ResolveModFiles(
{
modEntityId = file.Mod.Resolve(db, tx);
modPageIds[uidForMod] = modEntityId;
await ResolveAllFilesInModPage(uidForMod, tx, modEntityId, CancellationToken.None);
}

var fileEntityId = file.Resolve(db, tx, modEntityId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public NexusModsLibrary(IServiceProvider serviceProvider)
foreach (var node in modInfo.Data!.LegacyMods.Nodes)
first = node.Resolve(_connection.Db, tx);

await ResolveAllFilesInModPage(uid, tx, first, cancellationToken);

var txResults = await tx.Commit();
return NexusModsModPageMetadata.Load(txResults.Db, txResults[first]);
}

private async Task ResolveAllFilesInModPage(UidForMod uid, ITransaction tx, EntityId modPageId, CancellationToken cancellationToken)
{
// Note(sewer):
// Make sure to also fetch all files on the mod page.
// The update code refreshes file info only on changes of the mod page.
Expand All @@ -85,10 +93,7 @@ public NexusModsLibrary(IServiceProvider serviceProvider)
var filesByUid = await _gqlClient.ModFiles.ExecuteAsync(modIdString, gameIdString, cancellationToken);
filesByUid.EnsureNoErrors();
foreach (var node in filesByUid.Data!.ModFiles)
node.Resolve(_connection.Db, tx, first);

var txResults = await tx.Commit();
return NexusModsModPageMetadata.Load(txResults.Db, txResults[first]);
node.Resolve(_connection.Db, tx, modPageId);
}

public async Task<NexusModsFileMetadata.ReadOnly> GetOrAddFile(
Expand Down

0 comments on commit 3f83845

Please sign in to comment.