Try hydrating timelines in a separate query instead of using relations
This commit is contained in:
parent
07d7b3868d
commit
1499f9b417
|
@ -4,6 +4,7 @@ import { type DittoFilter } from '@/interfaces/DittoFilter.ts';
|
|||
import { getFeedPubkeys } from '@/queries.ts';
|
||||
import { booleanParamSchema } from '@/schema.ts';
|
||||
import { eventsDB } from '@/storages.ts';
|
||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||
import { paginated, paginationSchema } from '@/utils/api.ts';
|
||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||
|
||||
|
@ -34,10 +35,9 @@ const hashtagTimelineController: AppController = (c) => {
|
|||
async function renderStatuses(c: AppContext, filters: DittoFilter[]) {
|
||||
const { signal } = c.req.raw;
|
||||
|
||||
const events = await eventsDB.query(
|
||||
filters.map((filter) => ({ ...filter, relations: ['author', 'event_stats', 'author_stats'] })),
|
||||
{ signal },
|
||||
);
|
||||
const events = await eventsDB
|
||||
.query(filters, { signal })
|
||||
.then((events) => hydrateEvents({ events, relations: ['author'], storage: eventsDB, signal }));
|
||||
|
||||
if (!events.length) {
|
||||
return c.json([]);
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
import { type NostrEvent, type NStore } from '@/deps.ts';
|
||||
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||
import { type DittoFilter } from '@/interfaces/DittoFilter.ts';
|
||||
import { type DittoRelation } from '@/interfaces/DittoFilter.ts';
|
||||
|
||||
interface HydrateEventOpts {
|
||||
events: DittoEvent[];
|
||||
filters: DittoFilter[];
|
||||
relations: DittoRelation[];
|
||||
storage: NStore;
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
|
||||
/** Hydrate event relationships using the provided storage. */
|
||||
async function hydrateEvents(opts: HydrateEventOpts): Promise<DittoEvent[]> {
|
||||
const { events, filters, storage, signal } = opts;
|
||||
const { events, relations, storage, signal } = opts;
|
||||
|
||||
if (filters.some((filter) => filter.relations?.includes('author'))) {
|
||||
if (events.length === 0) {
|
||||
return events;
|
||||
}
|
||||
|
||||
if (relations.includes('author')) {
|
||||
const pubkeys = new Set([...events].map((event) => event.pubkey));
|
||||
const authors = await storage.query([{ kinds: [0], authors: [...pubkeys] }], { signal });
|
||||
|
||||
|
|
|
@ -62,7 +62,12 @@ class SearchStore implements NStore {
|
|||
events.add(event);
|
||||
}
|
||||
|
||||
return hydrateEvents({ events: [...events], filters, storage: this.#hydrator, signal: opts?.signal });
|
||||
return hydrateEvents({
|
||||
events: [...events],
|
||||
relations: ['author', 'event_stats', 'author_stats'],
|
||||
storage: this.#hydrator,
|
||||
signal: opts?.signal,
|
||||
});
|
||||
} else {
|
||||
this.#debug(`Searching for "${query}" locally...`);
|
||||
return this.#fallback.query(filters, opts);
|
||||
|
|
Loading…
Reference in New Issue