[backend/core] Use AsyncKeyedLocker in NoteService (ISH-227)
This commit is contained in:
parent
d4e8d7a6f6
commit
7c6d55739e
1 changed files with 17 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using AsyncKeyedLock;
|
||||
using Iceshrimp.Backend.Core.Configuration;
|
||||
using Iceshrimp.Backend.Core.Database;
|
||||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
|
@ -49,6 +50,12 @@ public class NoteService(
|
|||
private readonly List<string> _resolverHistory = [];
|
||||
private int _recursionLimit = DefaultRecursionLimit;
|
||||
|
||||
private static readonly AsyncKeyedLocker<string> KeyedLocker = new(o =>
|
||||
{
|
||||
o.PoolSize = 100;
|
||||
o.PoolInitialFill = 5;
|
||||
});
|
||||
|
||||
public async Task<Note> CreateNoteAsync(
|
||||
User user, Note.NoteVisibility visibility, string? text = null, string? cw = null, Note? reply = null,
|
||||
Note? renote = null, IReadOnlyCollection<DriveFile>? attachments = null, Poll? poll = null,
|
||||
|
@ -1020,6 +1027,8 @@ public class NoteService(
|
|||
|
||||
var actor = await userResolver.ResolveAsync(attrTo.Id);
|
||||
|
||||
using (await KeyedLocker.LockAsync(uri))
|
||||
{
|
||||
try
|
||||
{
|
||||
return await ProcessNoteAsync(fetchedNote, actor, user);
|
||||
|
@ -1030,6 +1039,7 @@ public class NoteService(
|
|||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Note?> ResolveNoteAsync(ASNote note)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue