Update recompute script

This commit is contained in:
Alex Gleason 2024-05-14 18:50:05 -05:00
parent 47bc551e0b
commit 99a6c668c8
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 8 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import { db } from '@/db.ts'; import { DittoDB } from '@/db/DittoDB.ts';
import { DittoTables } from '@/db/DittoTables.ts'; import { DittoTables } from '@/db/DittoTables.ts';
import { Storages } from '@/storages.ts'; import { Storages } from '@/storages.ts';
@ -17,16 +17,19 @@ try {
Deno.exit(1); Deno.exit(1);
} }
const [followList] = await Storages.db.query([{ kinds: [3], authors: [pubkey], limit: 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'] = { const authorStats: DittoTables['author_stats'] = {
pubkey, pubkey,
followers_count: (await Storages.db.count([{ kinds: [3], '#p': [pubkey] }])).count, followers_count: (await store.count([{ kinds: [3], '#p': [pubkey] }])).count,
following_count: followList?.tags.filter(([name]) => name === 'p')?.length ?? 0, following_count: followList?.tags.filter(([name]) => name === 'p')?.length ?? 0,
notes_count: (await Storages.db.count([{ kinds: [1], authors: [pubkey] }])).count, notes_count: (await store.count([{ kinds: [1], authors: [pubkey] }])).count,
}; };
await db.insertInto('author_stats') await kysely.insertInto('author_stats')
.values(authorStats) .values(authorStats)
.onConflict((oc) => .onConflict((oc) =>
oc oc