[backend/core] Attach user entity to database change tracker in GetOrCreateSystemUserAsync
This prevents erroneous insert attempts when the data comes from the cache instead of the database.
This commit is contained in:
parent
b23348cde9
commit
8d14b04821
1 changed files with 4 additions and 1 deletions
|
@ -46,7 +46,7 @@ public class SystemUserService(ILogger<SystemUserService> logger, DatabaseContex
|
||||||
|
|
||||||
private async Task<User> GetOrCreateSystemUserAsync(string username)
|
private async Task<User> GetOrCreateSystemUserAsync(string username)
|
||||||
{
|
{
|
||||||
return await cache.FetchAsync($"systemUser:{username}", TimeSpan.FromHours(24), async () =>
|
var user = await cache.FetchAsync($"systemUser:{username}", TimeSpan.FromHours(24), async () =>
|
||||||
{
|
{
|
||||||
using (await KeyedLocker.LockAsync(username.ToLowerInvariant()))
|
using (await KeyedLocker.LockAsync(username.ToLowerInvariant()))
|
||||||
{
|
{
|
||||||
|
@ -56,6 +56,9 @@ public class SystemUserService(ILogger<SystemUserService> logger, DatabaseContex
|
||||||
await CreateSystemUserAsync(username);
|
await CreateSystemUserAsync(username);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
db.Attach(user);
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<User> CreateSystemUserAsync(string username)
|
private async Task<User> CreateSystemUserAsync(string username)
|
||||||
|
|
Loading…
Add table
Reference in a new issue