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

Fix update operation #11

Merged
merged 1 commit into from
Nov 25, 2023
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
20 changes: 18 additions & 2 deletions GuildWarsPartySearch/Services/Database/TableStorageDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public async Task<bool> SetPartySearches(Campaign campaign, Continent continent,
var scopedLogger = this.logger.CreateScopedLogger(nameof(this.SetPartySearches), partitionKey);
try
{
scopedLogger.LogInformation("Retrieving existing entries");
var existingEntries = await this.GetPartySearches(campaign, continent, region, map, district, cancellationToken);
var entries = partySearch.Select(e =>
{
var rowKey = e.CharName ?? string.Empty;
Expand All @@ -95,9 +97,23 @@ public async Task<bool> SetPartySearches(Campaign campaign, Continent continent,
};
});

var actions = new List<TableTransactionAction>();
if (existingEntries is not null)
{
scopedLogger.LogInformation("Patching nonexisting entries");
// Find all existing entries that don't exist in the update. For those, queue a delete transaction
actions.AddRange(existingEntries
.Where(e => entries.FirstOrDefault(e2 => e.CharName == e2.CharName) is null)
.Select(e => new TableTransactionAction(TableTransactionActionType.Delete, new PartySearchTableEntity
{
PartitionKey = partitionKey,
RowKey = e.CharName ?? string.Empty,
})));
}

scopedLogger.LogInformation("Batch transaction");
var transactions = entries.Select(e => new TableTransactionAction(TableTransactionActionType.UpsertReplace, e));
var responses = await this.tableClient.SubmitTransactionAsync(transactions, cancellationToken);
actions.AddRange(entries.Select(e => new TableTransactionAction(TableTransactionActionType.UpsertReplace, e)));
var responses = await this.tableClient.SubmitTransactionAsync(actions, cancellationToken);
foreach(var response in responses.Value)
{
scopedLogger.LogInformation($"[{response.Status}] {response.ReasonPhrase}");
Expand Down
Loading