Skip to content

Commit

Permalink
WIP: Fix Mod Page Caching being Borked
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Jan 20, 2025
1 parent 166753e commit a28e77d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public partial class NexusModsModPageMetadata : IModelDefinition
/// </summary>
public static readonly TimestampAttribute UpdatedAt = new(Namespace, nameof(UpdatedAt));

/// <summary>
/// The last time a full update of this page info was performed in the data store.
/// This is used for local caching.
/// </summary>
public static readonly TimestampAttribute DataUpdatedAt = new(Namespace, nameof(DataUpdatedAt));

/// <summary>
/// Uri for the full sized picture of the mod.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ public struct PageMetadataMixin : IModFeedItem
/// <summary/>
public EntityId GetModPageEntityId() => _metadata.Id;

/// <inheritodc/>
public DateTime GetLastUpdatedDateUtc() => _metadata.UpdatedAt.DateTime; // <= TODO: Change this with 'last file updated at' when V2 supports this field.
/// <inheritdoc/>
public DateTime GetLastUpdatedDateUtc()
{
// Local update time in database. Not on remote server.
if (NexusModsModPageMetadata.DataUpdatedAt.TryGetValue(_metadata, out var result))
return result.DateTime;

// If not in DB for whatever reason, default to min, will be refreshed on next
// update check.
return DateTime.MinValue;
}

/// <summary>
/// Returns the database entries containing page metadata(s) as a mixin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public PerFeedCacheUpdater(TUpdateableItem[] items, TimeSpan expiry)
{
_items = items;
DebugVerifyAllItemsAreFromSameGame();

_actions = new CacheUpdaterAction[items.Length];
_itemToIndex = new Dictionary<ModId, int>(items.Length);
for (var x = 0; x < _items.Length; x++)
Expand All @@ -66,8 +66,11 @@ public PerFeedCacheUpdater(TUpdateableItem[] items, TimeSpan expiry)
var minCachedDate = utcNow - expiry;
for (var x = 0; x < _items.Length; x++)
{
if (_items[x].GetLastUpdatedDateUtc() < minCachedDate)
var lastUpdatedDate = _items[x].GetLastUpdatedDateUtc();
if (lastUpdatedDate < minCachedDate)
_actions[x] = CacheUpdaterAction.NeedsUpdate;
else if (lastUpdatedDate >= minCachedDate)
_actions[x] = CacheUpdaterAction.UpdateLastCheckedTimestamp;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public static EntityId Resolve(this IModFragment modFragment, IDb db, ITransacti

if (Uri.TryCreate(modFragment.ThumbnailUrl, UriKind.Absolute, out var thumbnailUri))
nexusModResolver.Add(NexusModsModPageMetadata.ThumbnailUri, thumbnailUri);

nexusModResolver.Add(NexusModsModPageMetadata.DataUpdatedAt, DateTimeOffset.UtcNow);
return nexusModResolver.Id;
}

Expand Down

0 comments on commit a28e77d

Please sign in to comment.