From a76721994412d03f478356ce95de17814dfbb082 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Tue, 8 Oct 2024 00:10:39 +0700 Subject: [PATCH] instead of looking up all snapshot ids when there's more than 10 commits, lookup just the ids for entities changed --- src/SIL.Harmony/DataModel.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/SIL.Harmony/DataModel.cs b/src/SIL.Harmony/DataModel.cs index c8976f2..89be491 100644 --- a/src/SIL.Harmony/DataModel.cs +++ b/src/SIL.Harmony/DataModel.cs @@ -151,10 +151,13 @@ private async Task UpdateSnapshots(Commit oldestAddedCommit, Commit[] newCommits { await _crdtRepository.DeleteStaleSnapshots(oldestAddedCommit); Dictionary snapshotLookup; - //this is a performance optimization to avoid loading all the snapshots, this number is somewhat arbitrary if (newCommits.Length > 10) { - snapshotLookup = await _crdtRepository.CurrentSnapshots().ToDictionaryAsync(s => s.EntityId, s => (Guid?) s.Id); + var entityIds = newCommits.SelectMany(c => c.ChangeEntities.Select(ce => ce.EntityId)); + snapshotLookup = await _crdtRepository.CurrentSnapshots() + .Where(s => entityIds.Contains(s.EntityId)) + .Select(s => new KeyValuePair(s.EntityId, s.Id)) + .ToDictionaryAsync(s => s.Key, s => s.Value); } else {