Skip to content

Commit

Permalink
Ignore duplicate inserts in the same subscription update (#92)
Browse files Browse the repository at this point in the history
## Description of Changes

Ignore duplicate inserts in the same subscription update

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
  • Loading branch information
RReverser authored May 27, 2024
1 parent e12f14e commit d8ab45c
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 (row.Op != TableRowOperation.Types.OperationType.Insert)
{
Logger.LogWarning("Non-insert during a subscription update!");
continue;
}

if (!hashSet.Add(rowBytes))
{
// Ignore duplicate inserts in the same 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 d8ab45c

Please sign in to comment.