From b8a6d3186ce8019b3650cc6341f93a537efdbd28 Mon Sep 17 00:00:00 2001 From: cocoa-dev006 <93573337+cocoa-dev006@users.noreply.github.com> Date: Tue, 4 Oct 2022 11:30:04 +0900 Subject: [PATCH 1/3] change to save partition key in EventLogApi --- src/Covid19Radar.Api/V1EventLog.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Covid19Radar.Api/V1EventLog.cs b/src/Covid19Radar.Api/V1EventLog.cs index 9f4610715..a6bea8f37 100644 --- a/src/Covid19Radar.Api/V1EventLog.cs +++ b/src/Covid19Radar.Api/V1EventLog.cs @@ -139,6 +139,7 @@ public async Task RunAsync( ) { id = id, + PartitionKey = id, Created = timestamp, }; await _eventLogRepository.UpsertAsync(eventLogModel); From 9354d2f14d2c02efb1ac4fac995b7a887a278143 Mon Sep 17 00:00:00 2001 From: cocoa-dev006 <93573337+cocoa-dev006@users.noreply.github.com> Date: Tue, 4 Oct 2022 15:23:54 +0900 Subject: [PATCH 2/3] Add partition key logic to repositories --- .../DataAccess/CosmosEventLogRepository.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Covid19Radar.Api/DataAccess/CosmosEventLogRepository.cs b/src/Covid19Radar.Api/DataAccess/CosmosEventLogRepository.cs index 3908eac51..8a0fc6dd8 100644 --- a/src/Covid19Radar.Api/DataAccess/CosmosEventLogRepository.cs +++ b/src/Covid19Radar.Api/DataAccess/CosmosEventLogRepository.cs @@ -26,7 +26,12 @@ ILogger logger public async Task UpsertAsync(EventLogModel eventLog) { - ItemResponse recordAdded = await _db.EventLog.UpsertItemAsync(eventLog); + PartitionKey? pk = null; + if(eventLog.PartitionKey is null) + { + pk = new PartitionKey(eventLog.PartitionKey); + } + ItemResponse recordAdded = await _db.EventLog.UpsertItemAsync(eventLog, pk); _logger.LogInformation($"{nameof(UpsertAsync)} RequestCharge:{recordAdded.RequestCharge}"); } } From 1f6320e999e913b3865de70782240d69c163a3da Mon Sep 17 00:00:00 2001 From: cocoa-dev006 <93573337+cocoa-dev006@users.noreply.github.com> Date: Tue, 4 Oct 2022 16:40:01 +0900 Subject: [PATCH 3/3] fix conditional --- src/Covid19Radar.Api/DataAccess/CosmosEventLogRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Covid19Radar.Api/DataAccess/CosmosEventLogRepository.cs b/src/Covid19Radar.Api/DataAccess/CosmosEventLogRepository.cs index 8a0fc6dd8..8d8f64fdd 100644 --- a/src/Covid19Radar.Api/DataAccess/CosmosEventLogRepository.cs +++ b/src/Covid19Radar.Api/DataAccess/CosmosEventLogRepository.cs @@ -27,7 +27,7 @@ ILogger logger public async Task UpsertAsync(EventLogModel eventLog) { PartitionKey? pk = null; - if(eventLog.PartitionKey is null) + if(eventLog.PartitionKey is not null) { pk = new PartitionKey(eventLog.PartitionKey); }