mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
feat: add optional kysely in HydrateOpts interface
This commit is contained in:
parent
8e1826020c
commit
85fd7909e6
1 changed files with 14 additions and 9 deletions
|
|
@ -7,16 +7,19 @@ import { Conf } from '@/config.ts';
|
|||
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||
import { findQuoteTag } from '@/utils/tags.ts';
|
||||
import { findQuoteInContent } from '@/utils/note.ts';
|
||||
import { Kysely } from 'kysely';
|
||||
|
||||
interface HydrateOpts {
|
||||
events: DittoEvent[];
|
||||
store: NStore;
|
||||
signal?: AbortSignal;
|
||||
kysely?: Kysely<DittoTables>;
|
||||
}
|
||||
|
||||
/** Hydrate events using the provided storage. */
|
||||
async function hydrateEvents(opts: HydrateOpts): Promise<DittoEvent[]> {
|
||||
const { events, store, signal } = opts;
|
||||
const { events, store, signal, kysely = await DittoDB.getInstance() } = opts;
|
||||
console.log(kysely);
|
||||
|
||||
if (!events.length) {
|
||||
return events;
|
||||
|
|
@ -57,8 +60,8 @@ async function hydrateEvents(opts: HydrateOpts): Promise<DittoEvent[]> {
|
|||
}
|
||||
|
||||
const stats = {
|
||||
authors: await gatherAuthorStats(cache),
|
||||
events: await gatherEventStats(cache),
|
||||
authors: await gatherAuthorStats(cache, kysely),
|
||||
events: await gatherEventStats(cache, kysely),
|
||||
};
|
||||
|
||||
// Dedupe events.
|
||||
|
|
@ -276,7 +279,10 @@ function gatherReportedProfiles({ events, store, signal }: HydrateOpts): Promise
|
|||
}
|
||||
|
||||
/** Collect author stats from the events. */
|
||||
async function gatherAuthorStats(events: DittoEvent[]): Promise<DittoTables['author_stats'][]> {
|
||||
async function gatherAuthorStats(
|
||||
events: DittoEvent[],
|
||||
kysely: Kysely<DittoTables>,
|
||||
): Promise<DittoTables['author_stats'][]> {
|
||||
const pubkeys = new Set<string>(
|
||||
events
|
||||
.filter((event) => event.kind === 0)
|
||||
|
|
@ -287,8 +293,6 @@ async function gatherAuthorStats(events: DittoEvent[]): Promise<DittoTables['aut
|
|||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
const kysely = await DittoDB.getInstance();
|
||||
|
||||
const rows = await kysely
|
||||
.selectFrom('author_stats')
|
||||
.selectAll()
|
||||
|
|
@ -304,7 +308,10 @@ async function gatherAuthorStats(events: DittoEvent[]): Promise<DittoTables['aut
|
|||
}
|
||||
|
||||
/** Collect event stats from the events. */
|
||||
async function gatherEventStats(events: DittoEvent[]): Promise<DittoTables['event_stats'][]> {
|
||||
async function gatherEventStats(
|
||||
events: DittoEvent[],
|
||||
kysely: Kysely<DittoTables>,
|
||||
): Promise<DittoTables['event_stats'][]> {
|
||||
const ids = new Set<string>(
|
||||
events
|
||||
.filter((event) => event.kind === 1)
|
||||
|
|
@ -315,8 +322,6 @@ async function gatherEventStats(events: DittoEvent[]): Promise<DittoTables['even
|
|||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
const kysely = await DittoDB.getInstance();
|
||||
|
||||
const rows = await kysely
|
||||
.selectFrom('event_stats')
|
||||
.selectAll()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue