v3: various improvements and fixes to real-time updates
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 40s

This commit is contained in:
khannurien
2026-06-29 07:52:56 +00:00
parent f162d23ce3
commit aab5b5bfd5
12 changed files with 227 additions and 38 deletions

View File

@@ -169,13 +169,18 @@ export function notifyUserFollowersNewDump(
const createdAt = new Date().toISOString();
const sourceKey = `dump:${dumpId}`;
// Batch INSERT all follower notifications in a single statement
const params: (string | number | null)[] = [];
const placeholders: string[] = [];
// Insert per follower so we can broadcast only the rows that were actually
// created (INSERT OR IGNORE skips followers who already have this dump's
// notification) and reuse each persisted id in the live event — otherwise a
// later refetch would dedupe against a mismatched id and show a duplicate.
const insert = db.prepare(
`INSERT OR IGNORE INTO notifications (id, user_id, type, data, read, created_at, source_key)
VALUES (?, ?, ?, ?, 0, ?, ?);`,
);
for (const row of followerRows) {
const id = crypto.randomUUID();
placeholders.push("(?, ?, ?, ?, 0, ?, ?)");
params.push(
const result = insert.run(
id,
row.follower_id,
"user_dump_posted",
@@ -183,19 +188,11 @@ export function notifyUserFollowersNewDump(
createdAt,
sourceKey,
);
}
const result = db.prepare(
`INSERT OR IGNORE INTO notifications (id, user_id, type, data, read, created_at, source_key)
VALUES ${placeholders.join(", ")};`,
).run(...params);
if ((result.changes as number) > 0) {
for (const row of followerRows) {
if ((result.changes as number) > 0) {
sendToUser(row.follower_id, {
type: "notification_created",
notification: {
id: crypto.randomUUID(),
id,
userId: row.follower_id,
type: "user_dump_posted",
data,