@@ -38,19 +38,26 @@ private async Task ExecuteActionsAsync(IList list, CancellationToken cancellatio
38
38
}
39
39
list . Clear ( ) ;
40
40
await ( session . Batcher . ExecuteBatchAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
41
-
42
41
}
43
42
44
- private async Task AfterExecutionsAsync ( CancellationToken cancellationToken )
43
+ private Task PreInvalidateCachesAsync ( CancellationToken cancellationToken )
45
44
{
46
- cancellationToken . ThrowIfCancellationRequested ( ) ;
47
- if ( session . Factory . Settings . IsQueryCacheEnabled )
45
+ if ( cancellationToken . IsCancellationRequested )
48
46
{
49
- var spaces = executedSpaces . ToArray ( ) ;
50
- afterTransactionProcesses . AddSpacesToInvalidate ( spaces ) ;
51
- await ( session . Factory . UpdateTimestampsCache . PreInvalidateAsync ( spaces , cancellationToken ) ) . ConfigureAwait ( false ) ;
47
+ return Task . FromCanceled < object > ( cancellationToken ) ;
48
+ }
49
+ try
50
+ {
51
+ if ( session . Factory . Settings . IsQueryCacheEnabled )
52
+ {
53
+ return session . Factory . UpdateTimestampsCache . PreInvalidateAsync ( executedSpaces , cancellationToken ) ;
54
+ }
55
+ return Task . CompletedTask ;
56
+ }
57
+ catch ( Exception ex )
58
+ {
59
+ return Task . FromException < object > ( ex ) ;
52
60
}
53
- executedSpaces . Clear ( ) ;
54
61
}
55
62
56
63
public async Task ExecuteAsync ( IExecutable executable , CancellationToken cancellationToken )
@@ -62,23 +69,23 @@ public async Task ExecuteAsync(IExecutable executable, CancellationToken cancell
62
69
}
63
70
finally
64
71
{
65
- await ( AfterExecutionsAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
72
+ await ( PreInvalidateCachesAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
66
73
}
67
74
}
68
75
69
76
private async Task InnerExecuteAsync ( IExecutable executable , CancellationToken cancellationToken )
70
77
{
71
78
cancellationToken . ThrowIfCancellationRequested ( ) ;
72
- if ( executable . PropertySpaces != null )
73
- {
74
- executedSpaces . UnionWith ( executable . PropertySpaces ) ;
75
- }
76
79
try
77
80
{
78
81
await ( executable . ExecuteAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
79
82
}
80
83
finally
81
84
{
85
+ if ( executable . PropertySpaces != null )
86
+ {
87
+ executedSpaces . UnionWith ( executable . PropertySpaces ) ;
88
+ }
82
89
RegisterCleanupActions ( executable ) ;
83
90
}
84
91
}
@@ -96,7 +103,7 @@ public async Task ExecuteInsertsAsync(CancellationToken cancellationToken)
96
103
}
97
104
finally
98
105
{
99
- await ( AfterExecutionsAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
106
+ await ( PreInvalidateCachesAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
100
107
}
101
108
}
102
109
@@ -118,11 +125,11 @@ public async Task ExecuteActionsAsync(CancellationToken cancellationToken)
118
125
}
119
126
finally
120
127
{
121
- await ( AfterExecutionsAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
128
+ await ( PreInvalidateCachesAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
122
129
}
123
130
}
124
131
125
- private async Task PrepareActionsAsync ( IList queue , CancellationToken cancellationToken )
132
+ private static async Task PrepareActionsAsync ( IList queue , CancellationToken cancellationToken )
126
133
{
127
134
cancellationToken . ThrowIfCancellationRequested ( ) ;
128
135
foreach ( IExecutable executable in queue )
@@ -140,7 +147,7 @@ public async Task PrepareActionsAsync(CancellationToken cancellationToken)
140
147
await ( PrepareActionsAsync ( collectionUpdates , cancellationToken ) ) . ConfigureAwait ( false ) ;
141
148
await ( PrepareActionsAsync ( collectionCreations , cancellationToken ) ) . ConfigureAwait ( false ) ;
142
149
}
143
-
150
+
144
151
/// <summary>
145
152
/// Performs cleanup of any held cache softlocks.
146
153
/// </summary>
@@ -152,41 +159,27 @@ public Task AfterTransactionCompletionAsync(bool success, CancellationToken canc
152
159
{
153
160
return Task . FromCanceled < object > ( cancellationToken ) ;
154
161
}
155
- return afterTransactionProcesses . AfterTransactionCompletionAsync ( success , cancellationToken ) ;
162
+ try
163
+ {
164
+ afterTransactionProcesses . AfterTransactionCompletion ( success ) ;
165
+
166
+ return InvalidateCachesAsync ( cancellationToken ) ;
167
+ }
168
+ catch ( Exception ex )
169
+ {
170
+ return Task . FromException < object > ( ex ) ;
171
+ }
156
172
}
157
- private partial class AfterTransactionCompletionProcessQueue
173
+
174
+ private async Task InvalidateCachesAsync ( CancellationToken cancellationToken )
158
175
{
159
-
160
- public async Task AfterTransactionCompletionAsync ( bool success , CancellationToken cancellationToken )
176
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
177
+ if ( session . Factory . Settings . IsQueryCacheEnabled )
161
178
{
162
- cancellationToken . ThrowIfCancellationRequested ( ) ;
163
- int size = processes . Count ;
164
-
165
- for ( int i = 0 ; i < size ; i ++ )
166
- {
167
- try
168
- {
169
- AfterTransactionCompletionProcessDelegate process = processes [ i ] ;
170
- process ( success ) ;
171
- }
172
- catch ( CacheException e )
173
- {
174
- log . Error ( "could not release a cache lock" , e ) ;
175
- // continue loop
176
- }
177
- catch ( Exception e )
178
- {
179
- throw new AssertionFailure ( "Unable to perform AfterTransactionCompletion callback" , e ) ;
180
- }
181
- }
182
- processes . Clear ( ) ;
183
-
184
- if ( session . Factory . Settings . IsQueryCacheEnabled )
185
- {
186
- await ( session . Factory . UpdateTimestampsCache . InvalidateAsync ( querySpacesToInvalidate . ToArray ( ) , cancellationToken ) ) . ConfigureAwait ( false ) ;
187
- }
188
- querySpacesToInvalidate . Clear ( ) ;
179
+ await ( session . Factory . UpdateTimestampsCache . InvalidateAsync ( executedSpaces , cancellationToken ) ) . ConfigureAwait ( false ) ;
189
180
}
181
+
182
+ executedSpaces . Clear ( ) ;
190
183
}
191
184
}
192
185
}
0 commit comments