Skip to content

Commit

Permalink
don't return tracked objects from the dbContext to avoid clients modi…
Browse files Browse the repository at this point in the history
…fying objects which EF tracks (#21)
  • Loading branch information
hahn-kev authored Dec 11, 2024
1 parent 3a5d037 commit f400e26
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/QueryHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class QueryHelpers
{
public static async Task<SyncState> GetSyncState(this IQueryable<CommitBase> commits)
{
var dict = await commits.GroupBy(c => c.ClientId)
var dict = await commits.AsNoTracking().GroupBy(c => c.ClientId)
.Select(g => new { ClientId = g.Key, DateTime = g.Max(c => c.HybridDateTime.DateTime) })
.AsAsyncEnumerable()//this is so the ticks are calculated server side instead of the db
.ToDictionaryAsync(c => c.ClientId, c => c.DateTime.ToUnixTimeMilliseconds());
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony/Db/CrdtRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public IQueryable<T> GetCurrentObjects<T>() where T : class
{
if (_crdtConfig.Value.EnableProjectedTables)
{
return _dbContext.Set<T>();
return _dbContext.Set<T>().AsNoTracking();
}
throw new NotSupportedException("GetCurrentObjects is not supported when not using projected tables");
}
Expand Down

0 comments on commit f400e26

Please sign in to comment.