Move DittoFilter to @/types.ts, refactor db/events query
This commit is contained in:
parent
4580b921c4
commit
8f45f3a7ad
|
@ -1,7 +1,9 @@
|
||||||
import { db, type TagRow } from '@/db.ts';
|
import { db, type TagRow } from '@/db.ts';
|
||||||
import { type Filter, type Insertable } from '@/deps.ts';
|
import { type Insertable } from '@/deps.ts';
|
||||||
import { type SignedEvent } from '@/event.ts';
|
import { type SignedEvent } from '@/event.ts';
|
||||||
|
|
||||||
|
import type { DittoFilter } from '@/types.ts';
|
||||||
|
|
||||||
type TagCondition = ({ event, count }: { event: SignedEvent; count: number }) => boolean;
|
type TagCondition = ({ event, count }: { event: SignedEvent; count: number }) => boolean;
|
||||||
|
|
||||||
/** Conditions for when to index certain tags. */
|
/** Conditions for when to index certain tags. */
|
||||||
|
@ -42,19 +44,12 @@ function insertEvent(event: SignedEvent): Promise<void> {
|
||||||
return results;
|
return results;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
await Promise.all(tags.map((tag) => {
|
await trx.insertInto('tags')
|
||||||
return trx.insertInto('tags')
|
.values(tags)
|
||||||
.values(tag)
|
.execute();
|
||||||
.execute();
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Custom filter interface that extends Nostr filters with extra options for Ditto. */
|
|
||||||
interface DittoFilter<K extends number = number> extends Filter<K> {
|
|
||||||
local?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Build the query for a filter. */
|
/** Build the query for a filter. */
|
||||||
function getFilterQuery(filter: DittoFilter) {
|
function getFilterQuery(filter: DittoFilter) {
|
||||||
let query = db
|
let query = db
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { type Filter } from '@/deps.ts';
|
||||||
|
|
||||||
|
/** Custom filter interface that extends Nostr filters with extra options for Ditto. */
|
||||||
|
interface DittoFilter<K extends number = number> extends Filter<K> {
|
||||||
|
local?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { type DittoFilter };
|
Loading…
Reference in New Issue