Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Remove settings LoadAllUrlEntitiesOnStartup

support5d865f693909
diff --git a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs b/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
index 1739667f3..0ef1863fc 100644
--- a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
+++ b/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
@@ -36,19 +36,7 @@ namespace Grand.Business.Common.Services.Seo
}
#endregion
-
-
- /// <summary>
- /// Gets all cached URL Entity
- /// </summary>
- /// <returns>cached URL Entities</returns>
- protected virtual async Task<IList<EntityUrl>> GetAllUrlEntityCached()
- {
- //cache
- var key = string.Format(CacheKey.URLEntity_ALL_KEY);
- return await _cacheBase.GetAsync(key, async () => await Task.FromResult(_urlEntityRepository.Table.ToList()));
- }
-
+
#region Methods
/// <summary>
@@ -90,6 +78,7 @@ namespace Grand.Business.Common.Services.Seo
//cache
await _cacheBase.RemoveByPrefix(CacheKey.URLEntity_PATTERN_KEY);
}
+
/// <summary>
/// Deletes an URL Entity
/// </summary>
@@ -119,9 +108,9 @@ namespace Grand.Business.Common.Services.Seo
slug = slug.ToLowerInvariant();
var query = from ur in _urlEntityRepository.Table
- where ur.Slug == slug
- orderby ur.IsActive
- select ur;
+ where ur.Slug == slug
+ orderby ur.IsActive
+ select ur;
return await Task.FromResult(query.FirstOrDefault());
}
@@ -137,17 +126,6 @@ namespace Grand.Business.Common.Services.Seo
slug = slug.ToLowerInvariant();
- if (_config.LoadAllUrlEntitiesOnStartup)
- {
- var source = await GetAllUrlEntityCached();
- var query = from ur in source
- where ur.Slug != null && ur.Slug.Equals(slug, StringComparison.OrdinalIgnoreCase)
- orderby ur.IsActive
- select ur;
- var entityUrlForCaching = query.FirstOrDefault();
- return entityUrlForCaching;
- }
-
var key = string.Format(CacheKey.URLEntity_BY_SLUG_KEY, slug);
return await _cacheBase.GetAsync(key, async () =>
{
@@ -164,11 +142,11 @@ namespace Grand.Business.Common.Services.Seo
/// <param name="pageIndex">Page index</param>
/// <param name="pageSize">Page size</param>
/// <returns>URL Entity</returns>
- public virtual async Task<IPagedList<EntityUrl>> GetAllEntityUrl(string slug = "", bool? active = null, int pageIndex = 0, int pageSize = int.MaxValue)
+ public virtual async Task<IPagedList<EntityUrl>> GetAllEntityUrl(string slug = "", bool? active = null,
+ int pageIndex = 0, int pageSize = int.MaxValue)
{
-
var query = from p in _urlEntityRepository.Table
- select p;
+ select p;
if (!string.IsNullOrWhiteSpace(slug))
query = query.Where(ur => ur.Slug.Contains(slug.ToLowerInvariant()));
@@ -189,39 +167,20 @@ namespace Grand.Business.Common.Services.Seo
/// <returns>Found slug</returns>
public virtual async Task<string> GetActiveSlug(string entityId, string entityName, string languageId)
{
- if (_config.LoadAllUrlEntitiesOnStartup)
- {
- var key = string.Format(CacheKey.URLEntity_ACTIVE_BY_ID_NAME_LANGUAGE_KEY, entityId, entityName, languageId);
- return await _cacheBase.GetAsync(key, async () =>
- {
- var source = await GetAllUrlEntityCached();
- var query = from ur in source
- where ur.EntityId == entityId &&
- ur.EntityName == entityName &&
- ur.LanguageId == languageId &&
- ur.IsActive
- select ur.Slug;
- var slug = query.FirstOrDefault() ?? "";
- return slug;
- });
- }
- else
+ var key = string.Format(CacheKey.URLEntity_ACTIVE_BY_ID_NAME_LANGUAGE_KEY, entityId, entityName,
+ languageId);
+ return await _cacheBase.GetAsync(key, async () =>
{
- var key = string.Format(CacheKey.URLEntity_ACTIVE_BY_ID_NAME_LANGUAGE_KEY, entityId, entityName, languageId);
- return await _cacheBase.GetAsync(key, async () =>
- {
-
- var source = _urlEntityRepository.Table;
- var query = from ur in source
- where ur.EntityId == entityId &&
- ur.EntityName == entityName &&
- ur.LanguageId == languageId &&
- ur.IsActive
- select ur.Slug;
- var slug = await Task.FromResult(query.FirstOrDefault()) ?? "";
- return slug;
- });
- }
+ var source = _urlEntityRepository.Table;
+ var query = from ur in source
+ where ur.EntityId == entityId &&
+ ur.EntityName == entityName &&
+ ur.LanguageId == languageId &&
+ ur.IsActive
+ select ur.Slug;
+ var slug = await Task.FromResult(query.FirstOrDefault()) ?? "";
+ return slug;
+ });
}
/// <summary>
@@ -231,7 +190,8 @@ namespace Grand.Business.Common.Services.Seo
/// <param name="entity">Entity</param>
/// <param name="slug">Slug</param>
/// <param name="languageId">Language ID</param>
- public virtual async Task SaveSlug<T>(T entity, string slug, string languageId) where T : BaseEntity, ISlugEntity
+ public virtual async Task SaveSlug<T>(T entity, string slug, string languageId)
+ where T : BaseEntity, ISlugEntity
{
if (entity == null)
throw new ArgumentNullException(nameof(entity));
@@ -240,10 +200,10 @@ namespace Grand.Business.Common.Services.Seo
var entityName = typeof(T).Name;
var query = from ur in _urlEntityRepository.Table
- where ur.EntityId == entityId &&
- ur.EntityName == entityName &&
- ur.LanguageId == languageId
- select ur;
+ where ur.EntityId == entityId &&
+ ur.EntityName == entityName &&
+ ur.LanguageId == languageId
+ select ur;
var allUrlEntity = query.ToList();
var activeUrlEntity = allUrlEntity.FirstOrDefault(x => x.IsActive);
@@ -265,8 +225,7 @@ namespace Grand.Business.Common.Services.Seo
else
{
//new record
- var entityUrl = new EntityUrl
- {
+ var entityUrl = new EntityUrl {
EntityId = entityId,
EntityName = entityName,
Slug = slug,
@@ -301,8 +260,7 @@ namespace Grand.Business.Common.Services.Seo
else
{
//insert new record
- var entityUrl = new EntityUrl
- {
+ var entityUrl = new EntityUrl {
EntityId = entityId,
EntityName = entityName,
Slug = slug,
@@ -314,7 +272,6 @@ namespace Grand.Business.Common.Services.Seo
activeUrlEntity.IsActive = false;
await UpdateEntityUrl(activeUrlEntity);
}
-
}
}
}
diff --git a/src/Core/Grand.Infrastructure/Caching/Constants/CommonCacheKey.cs b/src/Core/Grand.Infrastructure/Caching/Constants/CommonCacheKey.cs
index fb418c6d9..13d358f18 100644
--- a/src/Core/Grand.Infrastructure/Caching/Constants/CommonCacheKey.cs
+++ b/src/Core/Grand.Infrastructure/Caching/Constants/CommonCacheKey.cs
@@ -136,11 +136,6 @@
/// </remarks>
public static string URLEntity_ACTIVE_BY_ID_NAME_LANGUAGE_KEY => "Grand.urlEntity.active.id-name-language-{0}-{1}-{2}";
- /// <summary>
- /// Key for caching
- /// </summary>
- public static string URLEntity_ALL_KEY => "Grand.urlEntity.all";
-
/// <summary>
/// Key for caching
/// </summary>
diff --git a/src/Core/Grand.Infrastructure/Configuration/PerformanceConfig.cs b/src/Core/Grand.Infrastructure/Configuration/PerformanceConfig.cs
index 54c10e67b..145536103 100644
--- a/src/Core/Grand.Infrastructure/Configuration/PerformanceConfig.cs
+++ b/src/Core/Grand.Infrastructure/Configuration/PerformanceConfig.cs
@@ -25,11 +25,6 @@ namespace Grand.Infrastructure.Configuration
/// </summary>
public bool DisplayMiniProfilerInPublicStore { get; set; }
- /// <summary>
- /// A value indicating whether to load all search engine friendly names (slugs) on application startup
- /// </summary>
- public bool LoadAllUrlEntitiesOnStartup { get; set; }
-
/// <summary>
/// Gets or sets a value indicating whether we compress response
/// </summary>
diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.json
index 931101e36..887e81f66 100644
--- a/src/Web/Grand.Web/App_Data/appsettings.json
+++ b/src/Web/Grand.Web/App_Data/appsettings.json
@@ -121,9 +121,6 @@
//Gets or sets a value indicating for default cache time in minutes"
"DefaultCacheTimeMinutes": 60,
- //A value indicating whether to load all search engine friendly names (slugs) on application startup
- "LoadAllUrlEntitiesOnStartup": false,
-
/// A value indicating whether to ignore ACL rules
"IgnoreAcl": false,