@@ -17,22 +17,27 @@ public static class KurrentDBProjectionManagementClientExtensions
1717 /// <summary>
1818 /// Attempts to create or update a join projection in the EventStore.
1919 /// </summary>
20- public static async Task TryCreateJoinProjection ( this KurrentDBProjectionManagementClient client ,
20+ /// <returns><c>true</c> if the projection was created or updated; <c>false</c> if it was already up-to-date and no change was applied.</returns>
21+ public static async Task < bool > TryCreateJoinProjection ( this KurrentDBProjectionManagementClient client ,
2122 KurrentDBClient esClient ,
2223 string outputStream , IEnumerable < string > eventTypes )
2324 {
2425 var query = CreateQuery ( outputStream , eventTypes ) ;
2526
2627 if ( await client . ListContinuousAsync ( ) . AnyAsync ( x => x . Name == outputStream ) )
27- await UpdateIfChanged ( client , esClient , outputStream , query ) ;
28+ return await UpdateIfChanged ( client , esClient , outputStream , query ) ;
2829 else
30+ {
2931 await CreateAndStoreHash ( client , esClient , outputStream , query ) ;
32+ return true ;
33+ }
3034 }
3135
3236 /// <summary>
3337 /// Ensures the existence and proper configuration of a lookup projection in the EventStore.
3438 /// </summary>
35- public static async Task EnsureLookupProjection ( this KurrentDBProjectionManagementClient client ,
39+ /// <returns><c>true</c> if the projection was created or updated; <c>false</c> if it was already up-to-date and no change was applied.</returns>
40+ public static async Task < bool > EnsureLookupProjection ( this KurrentDBProjectionManagementClient client ,
3641 KurrentDBClient esClient ,
3742 IProjectionRegister register ,
3843 string category , string eventProperty , string outputStreamCategory ,
@@ -42,15 +47,19 @@ public static async Task EnsureLookupProjection(this KurrentDBProjectionManageme
4247 $ "fromStreams(['$ce-{ category } ']).when( {{ \n $any : function(s,e) {{ \n if(e.body && e.body.{ eventProperty } ) {{\n linkTo('{ outputStreamCategory } -' + e.body.{ eventProperty } , e) \n }}\n \n }}\n }});";
4348
4449 if ( ( await register . Get ( outputStreamCategory ) ) != null )
45- await UpdateIfChanged ( client , esClient , outputStreamCategory , query , token ) ;
50+ return await UpdateIfChanged ( client , esClient , outputStreamCategory , query , token ) ;
4651 else
52+ {
4753 await CreateAndStoreHash ( client , esClient , outputStreamCategory , query , token ) ;
54+ return true ;
55+ }
4856 }
4957
5058 /// <summary>
5159 /// Attempts to create or update a join projection in the EventStore.
5260 /// </summary>
53- public static async Task TryCreateJoinProjection ( this KurrentDBProjectionManagementClient client ,
61+ /// <returns><c>true</c> if the projection was created or updated; <c>false</c> if it was already up-to-date and no change was applied.</returns>
62+ public static async Task < bool > TryCreateJoinProjection ( this KurrentDBProjectionManagementClient client ,
5463 KurrentDBClient esClient ,
5564 string outputStream , IProjectionRegister register , IEnumerable < string > eventTypes ,
5665 CancellationToken token = default )
@@ -62,20 +71,24 @@ public static async Task TryCreateJoinProjection(this KurrentDBProjectionManagem
6271 var query = CreateQuery ( outputStream , eventTypes ) ;
6372
6473 if ( ( await register . Get ( outputStream ) ) != null )
65- await UpdateIfChanged ( client , esClient , outputStream , query , token ) ;
74+ return await UpdateIfChanged ( client , esClient , outputStream , query , token ) ;
6675 else
76+ {
6777 await CreateAndStoreHash ( client , esClient , outputStream , query , token ) ;
78+ return true ;
79+ }
6880 }
6981
70- private static async Task UpdateIfChanged ( KurrentDBProjectionManagementClient client , KurrentDBClient esClient ,
82+ private static async Task < bool > UpdateIfChanged ( KurrentDBProjectionManagementClient client , KurrentDBClient esClient ,
7183 string outputStream , string query , CancellationToken token = default )
7284 {
7385 var newHash = ComputeQueryHash ( query ) ;
7486 var existing = await TryGetStoredQueryHash ( esClient , outputStream , token ) ;
75- if ( existing == newHash ) return ;
87+ if ( existing == newHash ) return false ;
7688
7789 await UpdateWithRetry ( client , outputStream , query , token ) ;
7890 await StoreQueryHash ( esClient , outputStream , newHash , token ) ;
91+ return true ;
7992 }
8093
8194 private static async Task CreateAndStoreHash ( KurrentDBProjectionManagementClient client , KurrentDBClient esClient ,
0 commit comments