[backend/core] Use KeyedLocker when resolving pinned notes (ISH-67)

This commit is contained in:
Laura Hausmann 2024-03-01 03:43:50 +01:00
parent 81059291c3
commit 5082f15e75
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -709,13 +709,17 @@ public class UserService(
private void UpdateUserPinnedNotesInBackground(ASActor actor, User user, bool force = false) private void UpdateUserPinnedNotesInBackground(ASActor actor, User user, bool force = false)
{ {
if (followupTaskSvc.IsBackgroundWorker && !force) return; if (followupTaskSvc.IsBackgroundWorker && !force) return;
if (KeyedLocker.IsInUse($"pinnedNotes:{user.Id}")) return;
_ = followupTaskSvc.ExecuteTask("UpdateUserPinnedNotes", async provider => _ = followupTaskSvc.ExecuteTask("UpdateUserPinnedNotes", async provider =>
{
using (await KeyedLocker.LockAsync($"pinnedNotes:{user.Id}"))
{ {
var bgDb = provider.GetRequiredService<DatabaseContext>(); var bgDb = provider.GetRequiredService<DatabaseContext>();
var bgNoteSvc = provider.GetRequiredService<NoteService>(); var bgNoteSvc = provider.GetRequiredService<NoteService>();
var bgUser = await bgDb.Users.IncludeCommonProperties().FirstOrDefaultAsync(p => p.Id == user.Id); var bgUser = await bgDb.Users.IncludeCommonProperties().FirstOrDefaultAsync(p => p.Id == user.Id);
if (bgUser == null) return; if (bgUser == null) return;
await bgNoteSvc.UpdatePinnedNotesAsync(actor, bgUser); await bgNoteSvc.UpdatePinnedNotesAsync(actor, bgUser);
}
}); });
} }