mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-25 16:24:20 +01:00
Add assembleEvents bench
This commit is contained in:
14
src/storages/hydrate.bench.ts
Normal file
14
src/storages/hydrate.bench.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { assembleEvents } from '@/storages/hydrate.ts';
|
||||
import { jsonlEvents } from '@/test.ts';
|
||||
|
||||
const testEvents = await jsonlEvents('fixtures/hydrated.jsonl');
|
||||
|
||||
Deno.bench('assembleEvents with home feed', (b) => {
|
||||
// The first 20 events in this file are my home feed.
|
||||
// The rest are events that would be hydrated by the store.
|
||||
const events = testEvents.slice(0, 20);
|
||||
|
||||
b.start();
|
||||
|
||||
assembleEvents(events, testEvents, { authors: [], events: [] });
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
import { assertEquals } from '@std/assert';
|
||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||
import { MockRelay } from '@nostrify/nostrify/test';
|
||||
import { assertEquals } from '@std/assert';
|
||||
|
||||
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||
import { eventFixture } from '@/test.ts';
|
||||
|
||||
Deno.test('hydrateEvents(): author --- WITHOUT stats', async () => {
|
||||
|
||||
@@ -67,7 +67,7 @@ async function hydrateEvents(opts: HydrateOpts): Promise<DittoEvent[]> {
|
||||
}
|
||||
|
||||
/** Connect the events in list `b` to the DittoEvent fields in list `a`. */
|
||||
function assembleEvents(
|
||||
export function assembleEvents(
|
||||
a: DittoEvent[],
|
||||
b: DittoEvent[],
|
||||
stats: { authors: DittoTables['author_stats'][]; events: DittoTables['event_stats'][] },
|
||||
|
||||
@@ -16,6 +16,12 @@ export async function eventFixture(name: string): Promise<NostrEvent> {
|
||||
return structuredClone(result.default);
|
||||
}
|
||||
|
||||
/** Import a JSONL fixture by name in tests. */
|
||||
export async function jsonlEvents(path: string): Promise<NostrEvent[]> {
|
||||
const data = await Deno.readTextFile(path);
|
||||
return data.split('\n').map((line) => JSON.parse(line));
|
||||
}
|
||||
|
||||
/** Generate an event for use in tests. */
|
||||
export function genEvent(t: Partial<NostrEvent> = {}, sk: Uint8Array = generateSecretKey()): NostrEvent {
|
||||
const event = finalizeEvent({
|
||||
|
||||
Reference in New Issue
Block a user