mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Remove forUpdate() call in stats
This commit is contained in:
parent
370deac1af
commit
b88f532e4c
1 changed files with 12 additions and 6 deletions
|
|
@ -302,23 +302,26 @@ export async function updateAuthorStats(
|
|||
search: '',
|
||||
};
|
||||
|
||||
// Try to update first - this is more efficient under high concurrency
|
||||
const prev = await kysely
|
||||
.selectFrom('author_stats')
|
||||
.selectAll()
|
||||
.forUpdate()
|
||||
.where('pubkey', '=', pubkey)
|
||||
.executeTakeFirst();
|
||||
|
||||
const stats = fn(prev ?? empty);
|
||||
|
||||
if (prev) {
|
||||
// Row exists, update it
|
||||
const stats = fn(prev);
|
||||
await kysely.updateTable('author_stats')
|
||||
.set(stats)
|
||||
.where('pubkey', '=', pubkey)
|
||||
.execute();
|
||||
} else {
|
||||
// Row doesn't exist, insert it
|
||||
const stats = fn(empty);
|
||||
await kysely.insertInto('author_stats')
|
||||
.values({ ...empty, ...stats })
|
||||
.onConflict((oc) => oc.column('pubkey').doUpdateSet(stats))
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
|
@ -352,23 +355,26 @@ export async function updateEventStats(
|
|||
reactions: '{}',
|
||||
};
|
||||
|
||||
// Try to update first - this is more efficient under high concurrency
|
||||
const prev = await kysely
|
||||
.selectFrom('event_stats')
|
||||
.selectAll()
|
||||
.forUpdate()
|
||||
.where('event_id', '=', eventId)
|
||||
.executeTakeFirst();
|
||||
|
||||
const stats = fn(prev ?? empty);
|
||||
|
||||
if (prev) {
|
||||
// Row exists, update it
|
||||
const stats = fn(prev);
|
||||
await kysely.updateTable('event_stats')
|
||||
.set(stats)
|
||||
.where('event_id', '=', eventId)
|
||||
.execute();
|
||||
} else {
|
||||
// Row doesn't exist, insert it
|
||||
const stats = fn(empty);
|
||||
await kysely.insertInto('event_stats')
|
||||
.values({ ...empty, ...stats })
|
||||
.onConflict((oc) => oc.column('event_id').doUpdateSet(stats))
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue