diff --git a/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs b/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs index b61daf7f7c51..5b1512ef5049 100644 --- a/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs +++ b/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs @@ -120,7 +120,7 @@ public async Task RebuildDatabaseCacheIfSerializerChangedAsync() private Task PerformRebuild() { using ICoreScope scope = _coreScopeProvider.CreateCoreScope(); - _databaseCacheRepository.Rebuild(); + _databaseCacheRepository.Rebuild([], [], []); // If the serializer type has changed, we also need to update it in the key value store. var currentSerializerValue = _keyValueService.GetValue(NuCacheSerializerKey); diff --git a/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs b/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs index b72af50a59e5..6e1df8b5d049 100644 --- a/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs +++ b/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs @@ -101,10 +101,11 @@ public void Rebuild( | ContentCacheDataSerializerEntityType.Media | ContentCacheDataSerializerEntityType.Member); - // If contentTypeIds, mediaTypeIds and memberTypeIds are null, truncate table as all records will be deleted (as these 3 are the only types in the table). - if (contentTypeIds != null && !contentTypeIds.Any() - && mediaTypeIds != null && !mediaTypeIds.Any() - && memberTypeIds != null && !memberTypeIds.Any()) + // If contentTypeIds, mediaTypeIds and memberTypeIds are all non-null but empty, + // truncate the table as all records will be deleted (as these 3 are the only types in the table). + if (contentTypeIds is not null && contentTypeIds.Count == 0 && + mediaTypeIds is not null && mediaTypeIds.Count == 0 && + memberTypeIds is not null && memberTypeIds.Count == 0) { if (Database.DatabaseType == DatabaseType.SqlServer2012) { @@ -280,10 +281,15 @@ await Database.InsertOrUpdateAsync( // assumes content tree lock private void RebuildContentDbCache(IContentCacheDataSerializer serializer, int groupSize, IReadOnlyCollection? contentTypeIds) { + if (contentTypeIds is null) + { + return; + } + Guid contentObjectType = Constants.ObjectTypes.Document; // remove all - if anything fails the transaction will rollback - if (contentTypeIds == null || contentTypeIds.Count == 0) + if (contentTypeIds.Count == 0) { // must support SQL-CE Database.Execute( @@ -310,7 +316,7 @@ SELECT id FROM umbracoNode // insert back - if anything fails the transaction will rollback IQuery query = SqlContext.Query(); - if (contentTypeIds != null && contentTypeIds.Count > 0) + if (contentTypeIds.Count > 0) { query = query.WhereIn(x => x.ContentTypeId, contentTypeIds); // assume number of ctypes won't blow IN(...) } @@ -345,13 +351,17 @@ SELECT id FROM umbracoNode } // assumes media tree lock - private void RebuildMediaDbCache(IContentCacheDataSerializer serializer, int groupSize, - IReadOnlyCollection? contentTypeIds) + private void RebuildMediaDbCache(IContentCacheDataSerializer serializer, int groupSize, IReadOnlyCollection? contentTypeIds) { + if (contentTypeIds is null) + { + return; + } + Guid mediaObjectType = Constants.ObjectTypes.Media; // remove all - if anything fails the transaction will rollback - if (contentTypeIds is null || contentTypeIds.Count == 0) + if (contentTypeIds.Count == 0) { // must support SQL-CE Database.Execute( @@ -378,7 +388,7 @@ SELECT id FROM umbracoNode // insert back - if anything fails the transaction will rollback IQuery query = SqlContext.Query(); - if (contentTypeIds is not null && contentTypeIds.Count > 0) + if (contentTypeIds.Count > 0) { query = query.WhereIn(x => x.ContentTypeId, contentTypeIds); // assume number of ctypes won't blow IN(...) } @@ -398,13 +408,17 @@ SELECT id FROM umbracoNode } // assumes member tree lock - private void RebuildMemberDbCache(IContentCacheDataSerializer serializer, int groupSize, - IReadOnlyCollection? contentTypeIds) + private void RebuildMemberDbCache(IContentCacheDataSerializer serializer, int groupSize, IReadOnlyCollection? contentTypeIds) { + if (contentTypeIds is null) + { + return; + } + Guid memberObjectType = Constants.ObjectTypes.Member; // remove all - if anything fails the transaction will rollback - if (contentTypeIds == null || contentTypeIds.Count == 0) + if (contentTypeIds.Count == 0) { // must support SQL-CE Database.Execute( @@ -431,7 +445,7 @@ SELECT id FROM umbracoNode // insert back - if anything fails the transaction will rollback IQuery query = SqlContext.Query(); - if (contentTypeIds != null && contentTypeIds.Count > 0) + if (contentTypeIds.Count > 0) { query = query.WhereIn(x => x.ContentTypeId, contentTypeIds); // assume number of ctypes won't blow IN(...) } diff --git a/src/Umbraco.PublishedCache.HybridCache/Services/MediaCacheService.cs b/src/Umbraco.PublishedCache.HybridCache/Services/MediaCacheService.cs index 0a8283279a7a..29095b1d0433 100644 --- a/src/Umbraco.PublishedCache.HybridCache/Services/MediaCacheService.cs +++ b/src/Umbraco.PublishedCache.HybridCache/Services/MediaCacheService.cs @@ -258,7 +258,7 @@ public async Task RebuildMemoryCacheByContentTypeAsync(IEnumerable mediaTyp public void Rebuild(IReadOnlyCollection contentTypeIds) { using ICoreScope scope = _scopeProvider.CreateCoreScope(); - _databaseCacheRepository.Rebuild(contentTypeIds.ToList()); + _databaseCacheRepository.Rebuild(mediaTypeIds: contentTypeIds.ToList()); IEnumerable mediaTypeKeys = contentTypeIds.Select(x => _idKeyMap.GetKeyForId(x, UmbracoObjectTypes.MediaType)) .Where(x => x.Success)