pipeline: don't store event if a deletion for it exists

This commit is contained in:
Alex Gleason 2023-09-05 20:29:35 -05:00
parent 97a3478b1a
commit 48195f02b3
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 12 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import { addRelays } from '@/db/relays.ts';
import { findUser } from '@/db/users.ts'; import { findUser } from '@/db/users.ts';
import { type Event, LRUCache } from '@/deps.ts'; import { type Event, LRUCache } from '@/deps.ts';
import { isEphemeralKind } from '@/kinds.ts'; import { isEphemeralKind } from '@/kinds.ts';
import * as mixer from '@/mixer.ts';
import { isLocallyFollowed } from '@/queries.ts'; import { isLocallyFollowed } from '@/queries.ts';
import { Sub } from '@/subs.ts'; import { Sub } from '@/subs.ts';
import { trends } from '@/trends.ts'; import { trends } from '@/trends.ts';
@ -49,8 +50,18 @@ const isAdminEvent = ({ pubkey }: Event): boolean => pubkey === Conf.pubkey;
/** Maybe store the event, if eligible. */ /** Maybe store the event, if eligible. */
async function storeEvent(event: Event, data: EventData): Promise<void> { async function storeEvent(event: Event, data: EventData): Promise<void> {
if (isEphemeralKind(event.kind)) return; if (isEphemeralKind(event.kind)) return;
if (data.user || isAdminEvent(event) || await isLocallyFollowed(event.pubkey)) { if (data.user || isAdminEvent(event) || await isLocallyFollowed(event.pubkey)) {
await eventsDB.insertEvent(event).catch(console.warn); const [deletion] = await mixer.getFilters(
[{ kinds: [5], authors: [event.pubkey], '#e': [event.id], limit: 1 }],
{ limit: 1, timeout: Time.seconds(1) },
);
if (deletion) {
return Promise.reject(new RelayError('blocked', 'event was deleted'));
} else {
await eventsDB.insertEvent(event).catch(console.warn);
}
} else { } else {
return Promise.reject(new RelayError('blocked', 'only registered users can post')); return Promise.reject(new RelayError('blocked', 'only registered users can post'));
} }