Skip to content

Commit

Permalink
instead of looking up all snapshot ids when there's more than 10 comm…
Browse files Browse the repository at this point in the history
…its, lookup just the ids for entities changed
  • Loading branch information
hahn-kev committed Oct 7, 2024
1 parent 39204db commit a767219
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/SIL.Harmony/DataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ private async Task UpdateSnapshots(Commit oldestAddedCommit, Commit[] newCommits
{
await _crdtRepository.DeleteStaleSnapshots(oldestAddedCommit);
Dictionary<Guid, Guid?> 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<Guid, Guid?>(s.EntityId, s.Id))
.ToDictionaryAsync(s => s.Key, s => s.Value);
}
else
{
Expand Down

0 comments on commit a767219

Please sign in to comment.