@@ -308,9 +308,14 @@ private string AppPublishedConfigsMd5CacheKey(string appId, string env)
308308 return $ "ConfigService_AppPublishedConfigsMd5Cache_{ appId } _{ env } ";
309309 }
310310
311- private string AppPublishedConfigsMd5CacheKeyWithInheritanced ( string appId , string env )
311+ private string AppPublishedConfigsMd5CacheKeyWithInheritance ( string appId , string env )
312312 {
313- return $ "ConfigService_AppPublishedConfigsMd5CacheWithInheritanced_{ appId } _{ env } ";
313+ return $ "ConfigService_AppPublishedConfigsMd5CacheWithInheritance_{ appId } _{ env } ";
314+ }
315+
316+ private string AppPublishTimelineVirtualIdCacheKey ( string appId , string env )
317+ {
318+ return $ "ConfigService_AppPublishTimelineVirtualIdWithCache_{ appId } _{ env } ";
314319 }
315320
316321 private void ClearAppPublishedConfigsMd5Cache ( string appId , string env )
@@ -319,9 +324,15 @@ private void ClearAppPublishedConfigsMd5Cache(string appId, string env)
319324 _memoryCache ? . Remove ( cacheKey ) ;
320325 }
321326
322- private void ClearAppPublishedConfigsMd5CacheWithInheritanced ( string appId , string env )
327+ private void ClearAppPublishedConfigsMd5CacheWithInheritance ( string appId , string env )
328+ {
329+ var cacheKey = AppPublishedConfigsMd5CacheKeyWithInheritance ( appId , env ) ;
330+ _memoryCache ? . Remove ( cacheKey ) ;
331+ }
332+
333+ private void ClearAppPublishTimelineVirtualIdCache ( string appId , string env )
323334 {
324- var cacheKey = AppPublishedConfigsMd5CacheKeyWithInheritanced ( appId , env ) ;
335+ var cacheKey = AppPublishTimelineVirtualIdCacheKey ( appId , env ) ;
325336 _memoryCache ? . Remove ( cacheKey ) ;
326337 }
327338
@@ -338,8 +349,10 @@ public async Task<bool> AddRangeAsync(List<Config> configs, string env)
338349 using var repository = _configRepositoryAccessor ( env ) ;
339350 await repository . InsertAsync ( configs ) ;
340351
341- ClearAppPublishedConfigsMd5Cache ( configs . First ( ) . AppId , env ) ;
342- ClearAppPublishedConfigsMd5CacheWithInheritanced ( configs . First ( ) . AppId , env ) ;
352+ var appId = configs . First ( ) . AppId ;
353+ ClearAppPublishedConfigsMd5Cache ( appId , env ) ;
354+ ClearAppPublishedConfigsMd5CacheWithInheritance ( appId , env ) ;
355+ ClearAppPublishTimelineVirtualIdCache ( appId , env ) ;
343356
344357 return true ;
345358 }
@@ -349,9 +362,9 @@ public async Task<bool> AddRangeAsync(List<Config> configs, string env)
349362 /// </summary>
350363 /// <param name="appId"></param>
351364 /// <returns></returns>
352- public async Task < List < Config > > GetPublishedConfigsByAppIdWithInheritanced ( string appId , string env )
365+ public async Task < List < Config > > GetPublishedConfigsByAppIdWithInheritance ( string appId , string env )
353366 {
354- var configs = await GetPublishedConfigsByAppIdWithInheritanced_Dictionary ( appId , env ) ;
367+ var configs = await GetPublishedConfigsByAppIdWithInheritance_Dictionary ( appId , env ) ;
355368
356369 return configs . Values . ToList ( ) ;
357370 }
@@ -361,7 +374,7 @@ public async Task<List<Config>> GetPublishedConfigsByAppIdWithInheritanced(strin
361374 /// </summary>
362375 /// <param name="appId"></param>
363376 /// <returns></returns>
364- public async Task < Dictionary < string , Config > > GetPublishedConfigsByAppIdWithInheritanced_Dictionary (
377+ public async Task < Dictionary < string , Config > > GetPublishedConfigsByAppIdWithInheritance_Dictionary (
365378 string appId , string env )
366379 {
367380 var apps = new List < string > ( ) ;
@@ -401,9 +414,9 @@ public async Task<Dictionary<string, Config>> GetPublishedConfigsByAppIdWithInhe
401414 return configs ;
402415 }
403416
404- public async Task < string > AppPublishedConfigsMd5WithInheritanced ( string appId , string env )
417+ public async Task < string > AppPublishedConfigsMd5WithInheritance ( string appId , string env )
405418 {
406- var configs = await GetPublishedConfigsByAppIdWithInheritanced ( appId , env ) ;
419+ var configs = await GetPublishedConfigsByAppIdWithInheritance ( appId , env ) ;
407420
408421 var keyStr = string . Join ( '&' , configs . Select ( c => GenerateKey ( c ) ) . ToArray ( ) . OrderBy ( k => k , StringComparer . Ordinal ) ) ;
409422 var valStr = string . Join ( '&' , configs . Select ( c => c . Value ) . ToArray ( ) . OrderBy ( v => v , StringComparer . Ordinal ) ) ;
@@ -417,15 +430,15 @@ public async Task<string> AppPublishedConfigsMd5WithInheritanced(string appId, s
417430 /// </summary>
418431 /// <param name="appId"></param>
419432 /// <returns></returns>
420- public async Task < string > AppPublishedConfigsMd5CacheWithInheritanced ( string appId , string env )
433+ public async Task < string > AppPublishedConfigsMd5CacheWithInheritance ( string appId , string env )
421434 {
422- var cacheKey = AppPublishedConfigsMd5CacheKeyWithInheritanced ( appId , env ) ;
435+ var cacheKey = AppPublishedConfigsMd5CacheKeyWithInheritance ( appId , env ) ;
423436 if ( _memoryCache != null && _memoryCache . TryGetValue ( cacheKey , out string md5 ) )
424437 {
425438 return md5 ;
426439 }
427440
428- md5 = await AppPublishedConfigsMd5WithInheritanced ( appId , env ) ;
441+ md5 = await AppPublishedConfigsMd5WithInheritance ( appId , env ) ;
429442
430443 var cacheOp = new MemoryCacheEntryOptions ( )
431444 . SetAbsoluteExpiration ( TimeSpan . FromSeconds ( 60 ) ) ;
@@ -614,7 +627,8 @@ public void Dispose()
614627 await uow ? . SaveChangesAsync ( ) ;
615628
616629 ClearAppPublishedConfigsMd5Cache ( appId , env ) ;
617- ClearAppPublishedConfigsMd5CacheWithInheritanced ( appId , env ) ;
630+ ClearAppPublishedConfigsMd5CacheWithInheritance ( appId , env ) ;
631+ ClearAppPublishTimelineVirtualIdCache ( appId , env ) ;
618632
619633 return ( true , publishTimelineNode . Id ) ;
620634 }
@@ -777,7 +791,8 @@ public async Task<bool> RollbackAsync(string publishTimelineId, string env)
777791 await uow ? . SaveChangesAsync ( ) ;
778792
779793 ClearAppPublishedConfigsMd5Cache ( appId , env ) ;
780- ClearAppPublishedConfigsMd5CacheWithInheritanced ( appId , env ) ;
794+ ClearAppPublishedConfigsMd5CacheWithInheritance ( appId , env ) ;
795+ ClearAppPublishTimelineVirtualIdCache ( appId , env ) ;
781796
782797 return true ;
783798 }
@@ -1077,5 +1092,61 @@ public async Task<bool> SaveKvListAsync(string kvString, string appId, string en
10771092
10781093 return ( "" , key ) ;
10791094 }
1095+
1096+ /// <summary>
1097+ /// Generate the virtual id representing the last publish timeline node of the app and its inherited apps.
1098+ /// </summary>
1099+ /// <param name="appId"></param>
1100+ /// <param name="env"></param>
1101+ /// <returns></returns>
1102+ public async Task < string > GetLastPublishTimelineVirtualIdAsync ( string appId , string env )
1103+ {
1104+ using var publishTimelineRepository = _publishTimelineRepositoryAccsssor ( env ) ;
1105+
1106+ var apps = new List < string > ( ) ;
1107+ var inheritanceApps = await _appService . GetInheritancedAppsAsync ( appId ) ;
1108+ for ( int i = 0 ; i < inheritanceApps . Count ; i ++ )
1109+ {
1110+ if ( inheritanceApps [ i ] . Enabled )
1111+ {
1112+ apps . Add ( inheritanceApps [ i ] . Id as string ) ; //后继承的排在后面
1113+ }
1114+ }
1115+
1116+ apps . Add ( appId ) ; //本应用放在最后
1117+
1118+ var ids = new List < string > ( ) ;
1119+
1120+ foreach ( var app in apps )
1121+ {
1122+ var id = await publishTimelineRepository . GetLastPublishTimelineNodeIdAsync ( app , env ) ;
1123+ ids . Add ( id ) ;
1124+ }
1125+
1126+ return string . Join ( '|' , ids ) ;
1127+ }
1128+
1129+ /// <summary>
1130+ /// Generate the virtual id representing the last publish timeline node of the app and its inherited apps, with cache.
1131+ /// </summary>
1132+ /// <param name="appId"></param>
1133+ /// <param name="env"></param>
1134+ /// <returns></returns>
1135+ public async Task < string > GetLastPublishTimelineVirtualIdAsyncWithCache ( string appId , string env )
1136+ {
1137+ var cacheKey = AppPublishTimelineVirtualIdCacheKey ( appId , env ) ;
1138+ if ( _memoryCache != null && _memoryCache . TryGetValue ( cacheKey , out string vId ) )
1139+ {
1140+ return vId ;
1141+ }
1142+
1143+ vId = await GetLastPublishTimelineVirtualIdAsync ( appId , env ) ;
1144+
1145+ var cacheOp = new MemoryCacheEntryOptions ( )
1146+ . SetAbsoluteExpiration ( TimeSpan . FromSeconds ( 60 ) ) ;
1147+ _memoryCache ? . Set ( cacheKey , vId , cacheOp ) ;
1148+
1149+ return vId ;
1150+ }
10801151 }
10811152}
0 commit comments