[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 System.Diagnostics.CodeAnalysis;
|
||||||
|
using AsyncKeyedLock;
|
||||||
using Iceshrimp.Backend.Core.Configuration;
|
using Iceshrimp.Backend.Core.Configuration;
|
||||||
using Iceshrimp.Backend.Core.Database;
|
using Iceshrimp.Backend.Core.Database;
|
||||||
using Iceshrimp.Backend.Core.Database.Tables;
|
using Iceshrimp.Backend.Core.Database.Tables;
|
||||||
|
@ -49,6 +50,12 @@ public class NoteService(
|
||||||
private readonly List<string> _resolverHistory = [];
|
private readonly List<string> _resolverHistory = [];
|
||||||
private int _recursionLimit = DefaultRecursionLimit;
|
private int _recursionLimit = DefaultRecursionLimit;
|
||||||
|
|
||||||
|
private static readonly AsyncKeyedLocker<string> KeyedLocker = new(o =>
|
||||||
|
{
|
||||||
|
o.PoolSize = 100;
|
||||||
|
o.PoolInitialFill = 5;
|
||||||
|
});
|
||||||
|
|
||||||
public async Task<Note> CreateNoteAsync(
|
public async Task<Note> CreateNoteAsync(
|
||||||
User user, Note.NoteVisibility visibility, string? text = null, string? cw = null, Note? reply = null,
|
User user, Note.NoteVisibility visibility, string? text = null, string? cw = null, Note? reply = null,
|
||||||
Note? renote = null, IReadOnlyCollection<DriveFile>? attachments = null, Poll? poll = 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);
|
var actor = await userResolver.ResolveAsync(attrTo.Id);
|
||||||
|
|
||||||
|
using (await KeyedLocker.LockAsync(uri))
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return await ProcessNoteAsync(fetchedNote, actor, user);
|
return await ProcessNoteAsync(fetchedNote, actor, user);
|
||||||
|
@ -1030,6 +1039,7 @@ public class NoteService(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<Note?> ResolveNoteAsync(ASNote note)
|
public async Task<Note?> ResolveNoteAsync(ASNote note)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue