[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:
Laura Hausmann 2024-06-21 17:20:12 +02:00
parent b23348cde9
commit 8d14b04821
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -46,7 +46,7 @@ public class SystemUserService(ILogger<SystemUserService> logger, DatabaseContex
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()))
{
@ -56,6 +56,9 @@ public class SystemUserService(ILogger<SystemUserService> logger, DatabaseContex
await CreateSystemUserAsync(username);
}
});
db.Attach(user);
return user;
}
private async Task<User> CreateSystemUserAsync(string username)