Skip to content

Commit 65f75c1

Browse files
dahliaclaude
andcommitted
Fix duplicate mention handling in remote posts
Prevents database constraint violations when a remote post mentions the same user multiple times by adding onConflictDoNothing to the mentions insert operation. Also improves error logging in the federation refresh endpoint. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 973005d commit 65f75c1

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Version 0.6.3
66

77
To be released.
88

9+
- Fixed a bug where remote posts mentioning the same user multiple times
10+
could not be retrieved due to database constraint violations.
11+
912

1013
Version 0.6.2
1114
-------------

src/federation/post.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ export async function persistPost(
381381
accountId: account.id,
382382
postId: post.id,
383383
})
384+
.onConflictDoNothing({
385+
target: [mentions.accountId, mentions.postId],
386+
})
384387
.returning();
385388
mentionRows.push(...result);
386389
}

src/pages/federation.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import federation from "../federation";
77
import { persistAccount } from "../federation/account";
88
import { isPost, persistPost } from "../federation/post";
99
import { loginRequired } from "../login";
10+
import { getLogger } from "@logtape/logtape";
11+
12+
const logger = getLogger(["hollo", "pages", "federation"]);
1013

1114
const data = new Hono();
1215

@@ -155,7 +158,9 @@ data.post("/refresh", async (c) => {
155158
await persistPost(db, object, c.req.url, { ...fedCtx, documentLoader });
156159
return c.redirect("/federation?done=refresh:post");
157160
}
158-
} catch {}
161+
} catch (error) {
162+
logger.error("Failed to refresh: {error}", { error });
163+
}
159164
}
160165
return c.redirect("/federation?error=refresh");
161166
});

0 commit comments

Comments
 (0)