Browse Source

Remove Name from PermissionGrantCacheItem. Also use hashset for a better performance.

pull/4493/head
Halil İbrahim Kalkan 6 years ago
parent
commit
fd321dde8c
  1. 5
      modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionGrantCacheItem.cs
  2. 12
      modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionStore.cs

5
modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionGrantCacheItem.cs

@ -5,8 +5,6 @@ namespace Volo.Abp.PermissionManagement
[Serializable] [Serializable]
public class PermissionGrantCacheItem public class PermissionGrantCacheItem
{ {
public string Name { get; set; } //TODO: Consider to remove this
public bool IsGranted { get; set; } public bool IsGranted { get; set; }
public PermissionGrantCacheItem() public PermissionGrantCacheItem()
@ -14,9 +12,8 @@ namespace Volo.Abp.PermissionManagement
} }
public PermissionGrantCacheItem(string name, bool isGranted) public PermissionGrantCacheItem(bool isGranted)
{ {
Name = name;
IsGranted = isGranted; IsGranted = isGranted;
} }

12
modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionStore.cs

@ -54,7 +54,7 @@ namespace Volo.Abp.PermissionManagement
Logger.LogDebug($"Not found in the cache: {cacheKey}"); Logger.LogDebug($"Not found in the cache: {cacheKey}");
cacheItem = new PermissionGrantCacheItem(name, false); cacheItem = new PermissionGrantCacheItem(false);
await SetCacheItemsAsync(providerName, providerKey, name, cacheItem); await SetCacheItemsAsync(providerName, providerKey, name, cacheItem);
@ -71,19 +71,21 @@ namespace Volo.Abp.PermissionManagement
Logger.LogDebug($"Getting all granted permissions from the repository for this provider name,key: {providerName},{providerKey}"); Logger.LogDebug($"Getting all granted permissions from the repository for this provider name,key: {providerName},{providerKey}");
var permissionGrants = await PermissionGrantRepository.GetListAsync(providerName, providerKey); var grantedPermissionsHashSet = new HashSet<string>(
(await PermissionGrantRepository.GetListAsync(providerName, providerKey)).Select(p => p.Name)
);
Logger.LogDebug($"Setting the cache items. Count: {permissions.Count}"); Logger.LogDebug($"Setting the cache items. Count: {permissions.Count}");
var cacheItems = new List<KeyValuePair<string, PermissionGrantCacheItem>>(); var cacheItems = new List<KeyValuePair<string, PermissionGrantCacheItem>>();
foreach (var permission in permissions) foreach (var permission in permissions)
{ {
var isGranted = permissionGrants.Any(pg => pg.Name == permission.Name); //TODO: Optimize? Dictionary/Hash var isGranted = grantedPermissionsHashSet.Contains(permission.Name);
cacheItems.Add(new KeyValuePair<string, PermissionGrantCacheItem>( cacheItems.Add(new KeyValuePair<string, PermissionGrantCacheItem>(
CalculateCacheKey(permission.Name, providerName, providerKey), CalculateCacheKey(permission.Name, providerName, providerKey),
new PermissionGrantCacheItem(permission.Name, isGranted)) new PermissionGrantCacheItem(isGranted))
); );
if (permission.Name == currentName) if (permission.Name == currentName)

Loading…
Cancel
Save