Skip to content

Commit f54fa7c

Browse files
Attemt to further optimize GetCorrespondenceByIdForSync (#1443)
Attemt to further optimize GetCorrespondenceByIdForSync with precompiled queries and minor tweaks, and a more explicit /specialized structure.
1 parent 4f22578 commit f54fa7c

File tree

9 files changed

+113
-94
lines changed

9 files changed

+113
-94
lines changed

Test/Altinn.Correspondence.Tests/TestingHandler/SyncCorrespondenceForwardingEventRequestTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async Task Process_NewForwardingEvents_AddedOK()
8181

8282
// Mock correspondence repository
8383
_correspondenceRepositoryMock
84-
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()))
84+
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, It.IsAny<CorrespondenceSyncType>(), It.IsAny<CancellationToken>()))
8585
.ReturnsAsync(correspondence);
8686
// Mock forwarding event repository
8787
_forwardingEventRepositoryMock
@@ -96,7 +96,7 @@ public async Task Process_NewForwardingEvents_AddedOK()
9696
Assert.Equal(correspondenceId, result.AsT0);
9797

9898
// Verify correct calls to Correspondence repository
99-
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, false, true, It.IsAny<CancellationToken>()), Times.Once);
99+
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.ForwardingEvents, It.IsAny<CancellationToken>()), Times.Once);
100100
_correspondenceRepositoryMock.VerifyNoOtherCalls();
101101

102102
_forwardingEventRepositoryMock.Verify(
@@ -194,7 +194,7 @@ public async Task Process_DuplicateForwardingEvents_NoneAdded()
194194

195195
// Mock correspondence repository
196196
_correspondenceRepositoryMock
197-
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()))
197+
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, It.IsAny<CorrespondenceSyncType>(), It.IsAny<CancellationToken>()))
198198
.ReturnsAsync(correspondence);
199199

200200
// Act
@@ -205,7 +205,7 @@ public async Task Process_DuplicateForwardingEvents_NoneAdded()
205205
Assert.Equal(correspondenceId, result.AsT0);
206206

207207
// Verify correct calls to Correspondence repository
208-
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, false, true, It.IsAny<CancellationToken>()), Times.Once);
208+
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.ForwardingEvents, It.IsAny<CancellationToken>()), Times.Once);
209209
_correspondenceRepositoryMock.VerifyNoOtherCalls();
210210
_forwardingEventRepositoryMock.VerifyNoOtherCalls();
211211
}
@@ -297,7 +297,7 @@ public async Task Process_DuplicateForwardingEvents_RealWorld_NoneAdded()
297297

298298
// Mock correspondence repository
299299
_correspondenceRepositoryMock
300-
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()))
300+
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, It.IsAny<CorrespondenceSyncType>(), It.IsAny<CancellationToken>()))
301301
.ReturnsAsync(correspondence);
302302

303303
// Act
@@ -308,7 +308,7 @@ public async Task Process_DuplicateForwardingEvents_RealWorld_NoneAdded()
308308
Assert.Equal(correspondenceId, result.AsT0);
309309

310310
// Verify correct calls to Correspondence repository
311-
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, false, true, It.IsAny<CancellationToken>()), Times.Once);
311+
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.ForwardingEvents, It.IsAny<CancellationToken>()), Times.Once);
312312
_correspondenceRepositoryMock.VerifyNoOtherCalls();
313313
_forwardingEventRepositoryMock.VerifyNoOtherCalls();
314314
}

Test/Altinn.Correspondence.Tests/TestingHandler/SyncCorrespondenceNotificationEventHandlerTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task Process_NotAvailable_NewReminderNotification_AddedOK()
6161

6262
// Mock correspondence repository
6363
_correspondenceRepositoryMock
64-
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()))
64+
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()))
6565
.ReturnsAsync(correspondence);
6666
_correspondenceNotificationRepositoryMock
6767
.Setup(x => x.AddNotification(It.IsAny<CorrespondenceNotificationEntity>(), It.IsAny<CancellationToken>()))
@@ -75,7 +75,7 @@ public async Task Process_NotAvailable_NewReminderNotification_AddedOK()
7575
Assert.Equal(correspondenceId, result.AsT0);
7676

7777
// Verify correct calls to Correspondence repository
78-
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()), Times.Once);
78+
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()), Times.Once);
7979
_correspondenceRepositoryMock.VerifyNoOtherCalls();
8080

8181
_correspondenceNotificationRepositoryMock.Verify(x => x.AddNotification(It.Is<CorrespondenceNotificationEntity>(n =>
@@ -119,7 +119,7 @@ public async Task Process_Available_NewReminderNotification_AddedOK()
119119

120120
// Mock correspondence repository
121121
_correspondenceRepositoryMock
122-
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()))
122+
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()))
123123
.ReturnsAsync(correspondence);
124124
_correspondenceNotificationRepositoryMock
125125
.Setup(x => x.AddNotification(It.IsAny<CorrespondenceNotificationEntity>(), It.IsAny<CancellationToken>()))
@@ -133,7 +133,7 @@ public async Task Process_Available_NewReminderNotification_AddedOK()
133133
Assert.Equal(correspondenceId, result.AsT0);
134134

135135
// Verify correct calls to Correspondence repository
136-
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()), Times.Once);
136+
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()), Times.Once);
137137
_correspondenceRepositoryMock.VerifyNoOtherCalls();
138138

139139
_correspondenceNotificationRepositoryMock.Verify(x => x.AddNotification(It.Is<CorrespondenceNotificationEntity>(n =>
@@ -186,7 +186,7 @@ public async Task Process_NotAvailable_MultipleNewNotifications_AddedOK()
186186

187187
// Mock correspondence repository
188188
_correspondenceRepositoryMock
189-
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()))
189+
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()))
190190
.ReturnsAsync(correspondence);
191191
_correspondenceNotificationRepositoryMock
192192
.Setup(x => x.AddNotification(It.IsAny<CorrespondenceNotificationEntity>(), It.IsAny<CancellationToken>()))
@@ -200,7 +200,7 @@ public async Task Process_NotAvailable_MultipleNewNotifications_AddedOK()
200200
Assert.Equal(correspondenceId, result.AsT0);
201201

202202
// Verify correct calls to Correspondence repository
203-
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()), Times.Once);
203+
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()), Times.Once);
204204
_correspondenceRepositoryMock.VerifyNoOtherCalls();
205205

206206
_correspondenceNotificationRepositoryMock.Verify(x => x.AddNotification(It.Is<CorrespondenceNotificationEntity>(n =>
@@ -245,7 +245,7 @@ public async Task Process_NotAvailable_DuplicateNotification_NotAdded()
245245

246246
// Mock correspondence repository
247247
_correspondenceRepositoryMock
248-
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()))
248+
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()))
249249
.ReturnsAsync(correspondence);
250250
_correspondenceNotificationRepositoryMock
251251
.Setup(x => x.AddNotification(It.IsAny<CorrespondenceNotificationEntity>(), It.IsAny<CancellationToken>()))
@@ -259,7 +259,7 @@ public async Task Process_NotAvailable_DuplicateNotification_NotAdded()
259259
Assert.Equal(correspondenceId, result.AsT0);
260260

261261
// Verify correct calls to Correspondence repository
262-
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()), Times.Once);
262+
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()), Times.Once);
263263
_correspondenceRepositoryMock.VerifyNoOtherCalls();
264264
// Verify that no new notification was added
265265
_correspondenceNotificationRepositoryMock.VerifyNoOtherCalls();
@@ -300,7 +300,7 @@ public async Task Process_NotAvailable_DuplicateNotificationWithOffset_NotAdded(
300300

301301
// Mock correspondence repository
302302
_correspondenceRepositoryMock
303-
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()))
303+
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()))
304304
.ReturnsAsync(correspondence);
305305
_correspondenceNotificationRepositoryMock
306306
.Setup(x => x.AddNotification(It.IsAny<CorrespondenceNotificationEntity>(), It.IsAny<CancellationToken>()))
@@ -314,7 +314,7 @@ public async Task Process_NotAvailable_DuplicateNotificationWithOffset_NotAdded(
314314
Assert.Equal(correspondenceId, result.AsT0);
315315

316316
// Verify correct calls to Correspondence repository
317-
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()), Times.Once);
317+
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()), Times.Once);
318318
_correspondenceRepositoryMock.VerifyNoOtherCalls();
319319
// Verify that no new notification was added
320320
_correspondenceNotificationRepositoryMock.VerifyNoOtherCalls();
@@ -345,7 +345,7 @@ public async Task Process_CorrespondenceNotFound_ReturnError()
345345

346346
// Mock correspondence repository
347347
_correspondenceRepositoryMock
348-
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()))
348+
.Setup(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()))
349349
.ReturnsAsync((CorrespondenceEntity?)null);
350350

351351
// Act
@@ -356,7 +356,7 @@ public async Task Process_CorrespondenceNotFound_ReturnError()
356356
Assert.Equal(System.Net.HttpStatusCode.NotFound, result.AsT1.StatusCode);
357357

358358
// Verify correct calls to Correspondence repository
359-
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, false, true, false, It.IsAny<CancellationToken>()), Times.Once);
359+
_correspondenceRepositoryMock.Verify(x => x.GetCorrespondenceByIdForSync(correspondenceId, CorrespondenceSyncType.NotificationEvents, It.IsAny<CancellationToken>()), Times.Once);
360360
_correspondenceRepositoryMock.VerifyNoOtherCalls();
361361
// Verify that no new notification was added
362362
_correspondenceNotificationRepositoryMock.VerifyNoOtherCalls();

0 commit comments

Comments
 (0)