Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V13: Clear username cache #17815

Open
wants to merge 2 commits into
base: release/13.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public MemberRepositoryUsernameCachePolicy(IAppPolicyCache cache, IScopeAccessor

return entity;
}

public void DeleteByUserName(string key, string? username)
{
var cacheKey = GetEntityCacheKey(key + username);
Cache.ClearByKey(cacheKey);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Logging;

Check notice on line 1 in src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/13.6)

✅ Getting better: Low Cohesion

The number of different responsibilities decreases from 7 to 6, threshold = 3. Cohesion is calculated using the LCOM4 metric. Low cohesion means that the module/class has multiple unrelated responsibilities, doing too many things and breaking the Single Responsibility Principle.

Check notice on line 1 in src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/13.6)

✅ Getting better: Primitive Obsession

The ratio of primitive types in function arguments decreases from 40.00% to 39.22%, threshold = 30.0%. The functions in this file have too many primitive types (e.g. int, double, float) in their function argument lists. Using many primitive types lead to the code smell Primitive Obsession. Avoid adding more primitive arguments.
using Microsoft.Extensions.Options;
using NPoco;
using Umbraco.Cms.Core;
Expand Down Expand Up @@ -38,6 +38,7 @@
private readonly ITagRepository _tagRepository;
private bool _passwordConfigInitialized;
private string? _passwordConfigJson;
private const string UsernameCacheKey = "uRepo_userNameKey+";

public MemberRepository(
IScopeAccessor scopeAccessor,
Expand Down Expand Up @@ -228,7 +229,7 @@
}

public IMember? GetByUsername(string? username) =>
_memberByUsernameCachePolicy.GetByUserName("uRepo_userNameKey+", username, PerformGetByUsername, PerformGetAllByUsername);
_memberByUsernameCachePolicy.GetByUserName(UsernameCacheKey, username, PerformGetByUsername, PerformGetAllByUsername);

public int[] GetMemberIds(string[] usernames)
{
Expand Down Expand Up @@ -508,6 +509,12 @@
return sql;
}

protected override void PersistDeletedItem(IMember entity)
{
_memberByUsernameCachePolicy.DeleteByUserName(UsernameCacheKey, entity.Username);
base.PersistDeletedItem(entity);
}

// TODO: move that one up to Versionable! or better: kill it!
protected override Sql<ISqlContext> GetBaseQuery(bool isCount) =>
GetBaseQuery(isCount ? QueryType.Count : QueryType.Single);
Expand Down Expand Up @@ -837,6 +844,8 @@

OnUowRefreshedEntity(new MemberRefreshNotification(entity, new EventMessages()));

_memberByUsernameCachePolicy.DeleteByUserName(UsernameCacheKey, entity.Username);

Check notice on line 848 in src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MemberRepository.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/13.6)

ℹ Getting worse: Complex Method

PersistUpdatedItem already has high cyclomatic complexity, and now it increases in Lines of Code from 101 to 102. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
entity.ResetDirtyProperties();
}

Expand Down
Loading