From 12414013d5f2d86095a4082f5cd6df859c3e01fb Mon Sep 17 00:00:00 2001 From: Chad Date: Fri, 10 Mar 2023 01:25:07 +1300 Subject: [PATCH] Faster full nucache table rebuild (#13501) * SQL Server Truncate when full nucache SQL rebuild. * Optimize truncate for SQL Lite * Remove comment. * Use current DB Types * I added a couple of formatting changes. --------- Co-authored-by: georgebid <91198628+georgebid@users.noreply.github.com> (cherry picked from commit be72c8147daaa0e96470c2aa53df7e72a38b3ab2) --- .../Persistence/NuCacheContentRepository.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs index cb2feb55c3..b7fac1e7bc 100644 --- a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs +++ b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs @@ -108,7 +108,23 @@ public class NuCacheContentRepository : RepositoryBase, INuCacheContentRepositor | ContentCacheDataSerializerEntityType.Media | ContentCacheDataSerializerEntityType.Member); - if(contentTypeIds != null) + // 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 (Database.DatabaseType == DatabaseType.SqlServer2012) + { + Database.Execute($"TRUNCATE TABLE cmsContentNu"); + } + + if (Database.DatabaseType == DatabaseType.SQLite) + { + Database.Execute($"DELETE FROM cmsContentNu"); + } + } + + if (contentTypeIds != null) { RebuildContentDbCache(serializer, _nucacheSettings.Value.SqlPageSize, contentTypeIds); }