Skip to content

Commit

Permalink
Remove settings LoadAllUrlEntitiesOnStartup
Browse files Browse the repository at this point in the history
  • Loading branch information
support committed Jul 24, 2023
1 parent e960c76 commit 5d865f6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 85 deletions.
101 changes: 29 additions & 72 deletions src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,7 @@ public SlugService(ICacheBase cacheBase,
}

#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>
Expand Down Expand Up @@ -90,6 +78,7 @@ public virtual async Task UpdateEntityUrl(EntityUrl urlEntity)
//cache
await _cacheBase.RemoveByPrefix(CacheKey.URLEntity_PATTERN_KEY);
}

/// <summary>
/// Deletes an URL Entity
/// </summary>
Expand Down Expand Up @@ -119,9 +108,9 @@ public virtual async Task<EntityUrl> GetBySlug(string slug)
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());
}

Expand All @@ -137,17 +126,6 @@ public virtual async Task<EntityUrl> GetBySlugCached(string slug)

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 () =>
{
Expand All @@ -164,11 +142,11 @@ orderby ur.IsActive
/// <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()));
Expand All @@ -189,39 +167,20 @@ public virtual async Task<IPagedList<EntityUrl>> GetAllEntityUrl(string slug = "
/// <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>
Expand All @@ -231,7 +190,8 @@ public virtual async Task<string> GetActiveSlug(string entityId, string entityNa
/// <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));
Expand All @@ -240,10 +200,10 @@ public virtual async Task SaveSlug<T>(T entity, string slug, string languageId)
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);
Expand All @@ -265,8 +225,7 @@ public virtual async Task SaveSlug<T>(T entity, string slug, string languageId)
else
{
//new record
var entityUrl = new EntityUrl
{
var entityUrl = new EntityUrl {
EntityId = entityId,
EntityName = entityName,
Slug = slug,
Expand Down Expand Up @@ -301,8 +260,7 @@ public virtual async Task SaveSlug<T>(T entity, string slug, string languageId)
else
{
//insert new record
var entityUrl = new EntityUrl
{
var entityUrl = new EntityUrl {
EntityId = entityId,
EntityName = entityName,
Slug = slug,
Expand All @@ -314,7 +272,6 @@ public virtual async Task SaveSlug<T>(T entity, string slug, string languageId)
activeUrlEntity.IsActive = false;
await UpdateEntityUrl(activeUrlEntity);
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ public static partial class CacheKey
/// </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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public partial class PerformanceConfig
/// </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>
Expand Down
3 changes: 0 additions & 3 deletions src/Web/Grand.Web/App_Data/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down

0 comments on commit 5d865f6

Please sign in to comment.