refactor: finish UX refactor and move events storage

This commit is contained in:
Andy Burke 2025-09-12 09:24:22 -07:00
parent 4347d20263
commit f760156651
10 changed files with 269 additions and 27 deletions

View file

@ -37,13 +37,34 @@ type TOPIC_EVENT_CACHE_ENTRY = {
eviction_timeout: number;
};
const TOPIC_EVENT_ID_MATCHER = /^(?<event_type>.*):(?<event_id>.*)$/;
const TOPIC_EVENTS: Record<string, TOPIC_EVENT_CACHE_ENTRY> = {};
export function get_events_collection_for_topic(topic_id: string): FSDB_COLLECTION<EVENT> {
TOPIC_EVENTS[topic_id] = TOPIC_EVENTS[topic_id] ?? {
collection: new FSDB_COLLECTION<EVENT>({
name: `topics/${topic_id.slice(0, 14)}/${topic_id.slice(0, 34)}/${topic_id}/events`,
id_field: 'id',
organize: by_lurid,
organize: (id) => {
TOPIC_EVENT_ID_MATCHER.lastIndex = 0;
const {
groups: {
event_type,
event_id
}
} = TOPIC_EVENT_ID_MATCHER.exec(id ?? '') ?? {
groups: {}
};
return [
event_type,
event_id.slice(0, 14),
event_id.slice(0, 34),
event_id,
`${event_id}.json`
];
},
indexers: {
creator_id: new FSDB_INDEXER_SYMLINKS<EVENT>({
name: 'creator_id',