[backend/core] Use KeyedLocker when resolving pinned notes (ISH-67)
This commit is contained in:
parent
81059291c3
commit
5082f15e75
1 changed files with 10 additions and 6 deletions
|
@ -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);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue