From 68dea6f0c3fa858981a6ef96ad70a61e6f0140d3 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Fri, 1 Sep 2023 19:26:53 -0700 Subject: [PATCH] fix: :bug: more strange unlock calls --- .../src/remote/activitypub/kernel/announce/note.ts | 11 +++++------ .../src/remote/activitypub/kernel/create/note.ts | 4 +--- .../src/remote/activitypub/kernel/delete/note.ts | 4 +--- .../backend/src/remote/activitypub/models/note.ts | 4 +--- packages/backend/src/services/chart/core.ts | 3 +-- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/packages/backend/src/remote/activitypub/kernel/announce/note.ts b/packages/backend/src/remote/activitypub/kernel/announce/note.ts index 6cdaa6166..acf8c8436 100644 --- a/packages/backend/src/remote/activitypub/kernel/announce/note.ts +++ b/packages/backend/src/remote/activitypub/kernel/announce/note.ts @@ -32,8 +32,6 @@ export default async function ( // Interrupt if you block the announcement destination if (await shouldBlockInstance(extractDbHost(uri))) return; - const unlock = await getApLock(uri); - try { // Check if something with the same URI is already registered const exist = await fetchNote(uri); @@ -60,9 +58,10 @@ export default async function ( throw e; } - if (!(await Notes.isVisibleForMe(renote, actor.id))) - return "skip: invalid actor for this activity"; - + if (renote != null && !(await Notes.isVisibleForMe(renote, actor.id))) { + console.log("skip: invalid actor for this activity"); + return; + } logger.info(`Creating the (Re)Note: ${uri}`); const activityAudience = await parseAudience( @@ -79,6 +78,6 @@ export default async function ( uri, }); } finally { - unlock(); + await getApLock(uri); } } diff --git a/packages/backend/src/remote/activitypub/kernel/create/note.ts b/packages/backend/src/remote/activitypub/kernel/create/note.ts index 09c492730..fe4cc0906 100644 --- a/packages/backend/src/remote/activitypub/kernel/create/note.ts +++ b/packages/backend/src/remote/activitypub/kernel/create/note.ts @@ -31,8 +31,6 @@ export default async function ( } } - const unlock = await getApLock(uri); - try { const exist = await fetchNote(note); if (exist) return "skip: note exists"; @@ -46,6 +44,6 @@ export default async function ( throw e; } } finally { - unlock(); + await getApLock(uri); } } diff --git a/packages/backend/src/remote/activitypub/kernel/delete/note.ts b/packages/backend/src/remote/activitypub/kernel/delete/note.ts index 69298e917..b37f7d25f 100644 --- a/packages/backend/src/remote/activitypub/kernel/delete/note.ts +++ b/packages/backend/src/remote/activitypub/kernel/delete/note.ts @@ -13,8 +13,6 @@ export default async function ( ): Promise { logger.info(`Deleting the Note: ${uri}`); - const unlock = await getApLock(uri); - try { const dbResolver = new DbResolver(); const note = await dbResolver.getNoteFromApId(uri); @@ -39,6 +37,6 @@ export default async function ( await deleteNode(actor, note); return "ok: note deleted"; } finally { - unlock(); + await getApLock(uri); } } diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index 391f669f3..8e305d719 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -415,8 +415,6 @@ export async function resolveNote( `host ${extractDbHost(uri)} is blocked`, ); - const unlock = await getApLock(uri); - try { //#region Returns if already registered with this server const exist = await fetchNote(uri); @@ -439,7 +437,7 @@ export async function resolveNote( // Since the attached Note Object may be disguised, always specify the uri and fetch it from the server. return await createNote(uri, resolver, true); } finally { - unlock(); + await getApLock(uri); } } diff --git a/packages/backend/src/services/chart/core.ts b/packages/backend/src/services/chart/core.ts index 36fe37326..2fce4de91 100644 --- a/packages/backend/src/services/chart/core.ts +++ b/packages/backend/src/services/chart/core.ts @@ -430,7 +430,6 @@ export default abstract class Chart { ? `${this.name}:${date}:${span}:${group}` : `${this.name}:${date}:${span}`; - const unlock = await getChartInsertLock(lockKey); try { // ロック内でもう1回チェックする const currentLog = (await repository.findOneBy({ @@ -466,7 +465,7 @@ export default abstract class Chart { return log; } finally { - unlock(); + await getChartInsertLock(lockKey); } }