pipeline: delete unattached-media rows when authoring an event
This commit is contained in:
parent
0d343fa190
commit
b9476ccbd6
|
@ -59,7 +59,16 @@ function getUnattachedMediaByIds(ids: string[]) {
|
|||
.execute();
|
||||
}
|
||||
|
||||
/** Delete rows as an event with media is being created. */
|
||||
function deleteAttachedMedia(pubkey: string, urls: string[]) {
|
||||
return db.deleteFrom('unattached_media')
|
||||
.where('pubkey', '=', pubkey)
|
||||
.where('url', 'in', urls)
|
||||
.execute();
|
||||
}
|
||||
|
||||
export {
|
||||
deleteAttachedMedia,
|
||||
deleteUnattachedMediaByUrl,
|
||||
getUnattachedMedia,
|
||||
getUnattachedMediaByIds,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Conf } from '@/config.ts';
|
||||
import * as eventsDB from '@/db/events.ts';
|
||||
import { addRelays } from '@/db/relays.ts';
|
||||
import { deleteAttachedMedia } from '@/db/unattached-media.ts';
|
||||
import { findUser } from '@/db/users.ts';
|
||||
import { type Event, LRUCache } from '@/deps.ts';
|
||||
import { isEphemeralKind } from '@/kinds.ts';
|
||||
|
@ -27,6 +28,7 @@ async function handleEvent(event: Event): Promise<void> {
|
|||
processDeletions(event),
|
||||
trackRelays(event),
|
||||
trackHashtags(event),
|
||||
processMedia(event, data),
|
||||
streamOut(event, data),
|
||||
broadcast(event, data),
|
||||
]);
|
||||
|
@ -120,6 +122,14 @@ function trackRelays(event: Event) {
|
|||
return addRelays([...relays]);
|
||||
}
|
||||
|
||||
/** Delete unattached media entries that are attached to the event. */
|
||||
function processMedia({ tags, pubkey }: Event, { user }: EventData) {
|
||||
if (user) {
|
||||
const urls = getTagSet(tags, 'media');
|
||||
return deleteAttachedMedia(pubkey, [...urls]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Determine if the event is being received in a timely manner. */
|
||||
const isFresh = (event: Event): boolean => eventAge(event) < Time.seconds(10);
|
||||
|
||||
|
|
Loading…
Reference in New Issue