Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore duplicate inserts in the same subscription update #92

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading