From cf2a12c8046b29c3fcf315d3a2598555175e1aee Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 7 Dec 2025 09:20:54 +0000 Subject: fix: remove queue triggers outside of updateTags transaction --- packages/trpc/routers/bookmarks.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index f68d5ada..15ded2bd 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -711,7 +711,7 @@ export const bookmarksAppRouter = router({ ) .use(ensureBookmarkOwnership) .mutation(async ({ input, ctx }) => { - return ctx.db.transaction(async (tx) => { + const res = await ctx.db.transaction(async (tx) => { // Detaches const idsToRemove: string[] = []; if (input.detach.length > 0) { @@ -822,28 +822,32 @@ export const bookmarksAppRouter = router({ ), ); - await triggerRuleEngineOnEvent(input.bookmarkId, [ - ...idsToRemove.map((t) => ({ + return { + bookmarkId: input.bookmarkId, + attached: allIds, + detached: idsToRemove, + }; + }); + + await Promise.allSettled([ + triggerRuleEngineOnEvent(input.bookmarkId, [ + ...res.detached.map((t) => ({ type: "tagRemoved" as const, tagId: t, })), - ...allIds.map((t) => ({ + ...res.attached.map((t) => ({ type: "tagAdded" as const, tagId: t, })), - ]); - await triggerSearchReindex(input.bookmarkId, { + ]), + triggerSearchReindex(input.bookmarkId, { groupId: ctx.user.id, - }); - await triggerWebhook(input.bookmarkId, "edited", ctx.user.id, { + }), + triggerWebhook(input.bookmarkId, "edited", ctx.user.id, { groupId: ctx.user.id, - }); - return { - bookmarkId: input.bookmarkId, - attached: allIds, - detached: idsToRemove, - }; - }); + }), + ]); + return res; }), getBrokenLinks: authedProcedure .output( -- cgit v1.2.3-70-g09d2