mirror of
https://github.com/aljazceru/ditto.git
synced 2026-02-15 18:34:19 +01:00
Add a function to recalculate author stats
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { nip19 } from 'nostr-tools';
|
||||
|
||||
import { DittoDB } from '@/db/DittoDB.ts';
|
||||
import { DittoTables } from '@/db/DittoTables.ts';
|
||||
import { Storages } from '@/storages.ts';
|
||||
import { refreshAuthorStats } from '@/stats.ts';
|
||||
|
||||
let pubkey: string;
|
||||
try {
|
||||
@@ -17,23 +15,4 @@ try {
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
const store = await Storages.db();
|
||||
const kysely = await DittoDB.getInstance();
|
||||
|
||||
const [followList] = await store.query([{ kinds: [3], authors: [pubkey], limit: 1 }]);
|
||||
|
||||
const authorStats: DittoTables['author_stats'] = {
|
||||
pubkey,
|
||||
followers_count: (await store.count([{ kinds: [3], '#p': [pubkey] }])).count,
|
||||
following_count: followList?.tags.filter(([name]) => name === 'p')?.length ?? 0,
|
||||
notes_count: (await store.count([{ kinds: [1], authors: [pubkey] }])).count,
|
||||
};
|
||||
|
||||
await kysely.insertInto('author_stats')
|
||||
.values(authorStats)
|
||||
.onConflict((oc) =>
|
||||
oc
|
||||
.column('pubkey')
|
||||
.doUpdateSet(authorStats)
|
||||
)
|
||||
.execute();
|
||||
await refreshAuthorStats(pubkey);
|
||||
|
||||
Reference in New Issue
Block a user