Skip to content

Commit cf2a12c

Browse files
committed
fix: remove queue triggers outside of updateTags transaction
1 parent 6180c66 commit cf2a12c

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

packages/trpc/routers/bookmarks.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ export const bookmarksAppRouter = router({
711711
)
712712
.use(ensureBookmarkOwnership)
713713
.mutation(async ({ input, ctx }) => {
714-
return ctx.db.transaction(async (tx) => {
714+
const res = await ctx.db.transaction(async (tx) => {
715715
// Detaches
716716
const idsToRemove: string[] = [];
717717
if (input.detach.length > 0) {
@@ -822,28 +822,32 @@ export const bookmarksAppRouter = router({
822822
),
823823
);
824824

825-
await triggerRuleEngineOnEvent(input.bookmarkId, [
826-
...idsToRemove.map((t) => ({
825+
return {
826+
bookmarkId: input.bookmarkId,
827+
attached: allIds,
828+
detached: idsToRemove,
829+
};
830+
});
831+
832+
await Promise.allSettled([
833+
triggerRuleEngineOnEvent(input.bookmarkId, [
834+
...res.detached.map((t) => ({
827835
type: "tagRemoved" as const,
828836
tagId: t,
829837
})),
830-
...allIds.map((t) => ({
838+
...res.attached.map((t) => ({
831839
type: "tagAdded" as const,
832840
tagId: t,
833841
})),
834-
]);
835-
await triggerSearchReindex(input.bookmarkId, {
842+
]),
843+
triggerSearchReindex(input.bookmarkId, {
836844
groupId: ctx.user.id,
837-
});
838-
await triggerWebhook(input.bookmarkId, "edited", ctx.user.id, {
845+
}),
846+
triggerWebhook(input.bookmarkId, "edited", ctx.user.id, {
839847
groupId: ctx.user.id,
840-
});
841-
return {
842-
bookmarkId: input.bookmarkId,
843-
attached: allIds,
844-
detached: idsToRemove,
845-
};
846-
});
848+
}),
849+
]);
850+
return res;
847851
}),
848852
getBrokenLinks: authedProcedure
849853
.output(

0 commit comments

Comments
 (0)