mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-10 17:14:20 +01:00
Add an EventStore interface, refactor eventsDB
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { type AppController } from '@/app.ts';
|
||||
import { Conf } from '@/config.ts';
|
||||
import * as eventsDB from '@/db/events.ts';
|
||||
import { eventsDB } from '@/db/events.ts';
|
||||
import { insertUser } from '@/db/users.ts';
|
||||
import { findReplyTag, nip19, z } from '@/deps.ts';
|
||||
import { type DittoFilter } from '@/filter.ts';
|
||||
@@ -151,7 +151,7 @@ const accountStatusesController: AppController = async (c) => {
|
||||
filter['#t'] = [tagged];
|
||||
}
|
||||
|
||||
let events = await eventsDB.getFilters([filter]);
|
||||
let events = await eventsDB.getEvents([filter]);
|
||||
|
||||
if (exclude_replies) {
|
||||
events = events.filter((event) => !findReplyTag(event));
|
||||
@@ -256,7 +256,7 @@ const favouritesController: AppController = async (c) => {
|
||||
const pubkey = c.get('pubkey')!;
|
||||
const params = paginationSchema.parse(c.req.query());
|
||||
|
||||
const events7 = await eventsDB.getFilters(
|
||||
const events7 = await eventsDB.getEvents(
|
||||
[{ kinds: [7], authors: [pubkey], ...params }],
|
||||
{ signal: AbortSignal.timeout(1000) },
|
||||
);
|
||||
@@ -265,7 +265,7 @@ const favouritesController: AppController = async (c) => {
|
||||
.map((event) => event.tags.find((tag) => tag[0] === 'e')?.[1])
|
||||
.filter((id): id is string => !!id);
|
||||
|
||||
const events1 = await eventsDB.getFilters(
|
||||
const events1 = await eventsDB.getEvents(
|
||||
[{ kinds: [1], ids, relations: ['author', 'event_stats', 'author_stats'] }],
|
||||
{
|
||||
signal: AbortSignal.timeout(1000),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type AppController } from '@/app.ts';
|
||||
import * as eventsDB from '@/db/events.ts';
|
||||
import { eventsDB } from '@/db/events.ts';
|
||||
import { paginated, paginationSchema } from '@/utils/web.ts';
|
||||
import { renderNotification } from '@/views/mastodon/notifications.ts';
|
||||
|
||||
@@ -7,7 +7,7 @@ const notificationsController: AppController = async (c) => {
|
||||
const pubkey = c.get('pubkey')!;
|
||||
const { since, until } = paginationSchema.parse(c.req.query());
|
||||
|
||||
const events = await eventsDB.getFilters(
|
||||
const events = await eventsDB.getEvents(
|
||||
[{ kinds: [1], '#p': [pubkey], since, until }],
|
||||
{ signal: AbortSignal.timeout(3000) },
|
||||
);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { type AppController } from '@/app.ts';
|
||||
import * as eventsDB from '@/db/events.ts';
|
||||
import { eventsDB } from '@/db/events.ts';
|
||||
import { z } from '@/deps.ts';
|
||||
import { configSchema, elixirTupleSchema } from '@/schemas/pleroma-api.ts';
|
||||
import { createAdminEvent } from '@/utils/web.ts';
|
||||
import { Conf } from '@/config.ts';
|
||||
|
||||
const frontendConfigController: AppController = async (c) => {
|
||||
const [event] = await eventsDB.getFilters([{
|
||||
const [event] = await eventsDB.getEvents([{
|
||||
kinds: [30078],
|
||||
authors: [Conf.pubkey],
|
||||
'#d': ['pub.ditto.frontendConfig'],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AppController } from '@/app.ts';
|
||||
import * as eventsDB from '@/db/events.ts';
|
||||
import { eventsDB } from '@/db/events.ts';
|
||||
import { type Event, nip19, z } from '@/deps.ts';
|
||||
import { type DittoFilter } from '@/filter.ts';
|
||||
import { booleanParamSchema } from '@/schema.ts';
|
||||
@@ -76,7 +76,7 @@ function searchEvents({ q, type, limit, account_id }: SearchQuery): Promise<Even
|
||||
filter.authors = [account_id];
|
||||
}
|
||||
|
||||
return eventsDB.getFilters([filter]);
|
||||
return eventsDB.getEvents([filter]);
|
||||
}
|
||||
|
||||
/** Get event kinds to search from `type` query param. */
|
||||
@@ -94,7 +94,7 @@ function typeToKinds(type: SearchQuery['type']): number[] {
|
||||
/** Resolve a searched value into an event, if applicable. */
|
||||
async function lookupEvent(query: SearchQuery, signal = AbortSignal.timeout(1000)): Promise<Event | undefined> {
|
||||
const filters = await getLookupFilters(query);
|
||||
const [event] = await eventsDB.getFilters(filters, { limit: 1, signal });
|
||||
const [event] = await eventsDB.getEvents(filters, { limit: 1, signal });
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as eventsDB from '@/db/events.ts';
|
||||
import { eventsDB } from '@/db/events.ts';
|
||||
import { z } from '@/deps.ts';
|
||||
import { type DittoFilter } from '@/filter.ts';
|
||||
import { getFeedPubkeys } from '@/queries.ts';
|
||||
@@ -33,7 +33,7 @@ const hashtagTimelineController: AppController = (c) => {
|
||||
|
||||
/** Render statuses for timelines. */
|
||||
async function renderStatuses(c: AppContext, filters: DittoFilter<1>[], signal = AbortSignal.timeout(1000)) {
|
||||
const events = await eventsDB.getFilters(
|
||||
const events = await eventsDB.getEvents(
|
||||
filters.map((filter) => ({ ...filter, relations: ['author', 'event_stats', 'author_stats'] })),
|
||||
{ signal },
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user