Skip to content

Commit

Permalink
Ignore duplicate inserts in the same subscription update
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed May 14, 2024
1 parent 3854c08 commit ad8bda0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/SpacetimeDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@ HashSet<byte[]> GetInsertHashSet(string tableName, int tableSize)
foreach (var row in update.TableRowOperations)
{
var rowBytes = row.Row.ToByteArray();

if (!hashSet.Add(rowBytes))
{
// Ignore duplicate inserts in the same subscription update.
continue;
}

if (row.Op != TableRowOperation.Types.OperationType.Insert)
{
Logger.LogWarning("Non-insert during a subscription update!");
continue;
}

stream.Position = 0;
stream.Write(rowBytes, 0, rowBytes.Length);
stream.Position = 0;
Expand All @@ -312,12 +325,6 @@ HashSet<byte[]> GetInsertHashSet(string tableName, int tableSize)
throw new Exception("Failed to deserialize row");
}

if (row.Op != TableRowOperation.Types.OperationType.Insert)
{
Logger.LogWarning("Non-insert during a subscription update!");
continue;
}

table.SetAndForgetDecodedValue(deserializedRow, out var obj);
var op = new DbOp
{
Expand All @@ -326,14 +333,7 @@ HashSet<byte[]> GetInsertHashSet(string tableName, int tableSize)
rowValue = deserializedRow,
};

if (!hashSet.Add(rowBytes))
{
Logger.LogError($"Multiple of the same insert in the same subscription update: table={table.ClientTableType.Name} rowBytes={rowBytes}");
}
else
{
dbOps.Add(op);
}
dbOps.Add(op);
}
}

Expand Down

0 comments on commit ad8bda0

Please sign in to comment.