From 2cea0813afd01b6ee16f5bfe7b5e5971bd6940b1 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Mon, 13 May 2024 16:08:47 +0100 Subject: [PATCH] Few more minor opts --- src/SpacetimeDBClient.cs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/SpacetimeDBClient.cs b/src/SpacetimeDBClient.cs index d2115b9a..29bad06a 100644 --- a/src/SpacetimeDBClient.cs +++ b/src/SpacetimeDBClient.cs @@ -406,7 +406,7 @@ HashSet GetInsertHashSet(string tableName, int tableSize) } var (insertOp, deleteOp) = op.insert is not null ? (op, oldOp) : (oldOp, op); - primaryKeyLookup[primaryKeyValue] = new DbOp + op = new DbOp { table = insertOp.table, delete = deleteOp.delete, @@ -414,10 +414,7 @@ HashSet GetInsertHashSet(string tableName, int tableSize) rowValue = insertOp.rowValue, }; } - else - { - primaryKeyLookup[primaryKeyValue] = op; - } + primaryKeyLookup[primaryKeyValue] = op; } else { @@ -506,23 +503,20 @@ void ExecuteStateDiff() { foreach (var table in clientDB.GetTables()) { - foreach (var rowBytes in table.entries.Keys) + if (!preProcessedMessage.inserts.TryGetValue(table.Name, out var hashSet)) { - if (!preProcessedMessage.inserts.TryGetValue(table.Name, out var hashSet)) - { - continue; - } + continue; + } - if (!hashSet.Contains(rowBytes)) + foreach (var (rowBytes, oldValue) in table.entries.Where(kv => !hashSet.Contains(kv.Key))) + { + dbOps.Add(new DbOp { + table = table, // This is a row that we had before, but we do not have it now. // This must have been a delete. - dbOps.Add(new DbOp - { - table = table, - delete = new(table.entries[rowBytes].Item2, rowBytes), - }); - } + delete = new(oldValue.Item2, rowBytes), + }); } } }