Skip to content

Commit

Permalink
Skip redundant transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMacocian committed Nov 27, 2023
1 parent 1cac7c3 commit 5bdd783
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion GuildWarsPartySearch/Services/Database/TableStorageDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,28 @@ public async Task<bool> SetPartySearches(Campaign campaign, Continent continent,
}

scopedLogger.LogInformation("Batch transaction");
actions.AddRange(entries.Select(e => new TableTransactionAction(TableTransactionActionType.UpsertReplace, e)));
actions.AddRange(entries
.Where(e =>
{
// Only update entries that have changed
var existingEntry = entries.FirstOrDefault(e2 => e2.RowKey == e.RowKey);
return e.Campaign != existingEntry?.Campaign ||
e.Continent != existingEntry?.Continent ||
e.Region != existingEntry?.Region ||
e.Map != existingEntry?.Map ||
e.District != existingEntry?.District ||
e.CharName != existingEntry?.CharName ||
e.PartySize != existingEntry?.PartySize ||
e.PartyMaxSize != existingEntry?.PartyMaxSize ||
e.Npcs != existingEntry?.Npcs;
})
.Select(e => new TableTransactionAction(TableTransactionActionType.UpsertReplace, e)));
if (actions.None())
{
scopedLogger.LogInformation("No change detected. Skipping operation");
return true;
}

var responses = await this.tableClient.SubmitTransactionAsync(actions, cancellationToken);
foreach(var response in responses.Value)
{
Expand Down

0 comments on commit 5bdd783

Please sign in to comment.