refactor: zones => topics

This commit is contained in:
Andy Burke 2025-09-10 12:51:27 -07:00
parent 20a5d1bc88
commit fac8f409f4
26 changed files with 470 additions and 469 deletions

View file

@ -32,16 +32,16 @@ export type EVENT = {
};
};
type ZONE_EVENT_CACHE_ENTRY = {
type TOPIC_EVENT_CACHE_ENTRY = {
collection: FSDB_COLLECTION<EVENT>;
eviction_timeout: number;
};
const ZONE_EVENTS: Record<string, ZONE_EVENT_CACHE_ENTRY> = {};
export function get_events_collection_for_zone(zone_id: string): FSDB_COLLECTION<EVENT> {
ZONE_EVENTS[zone_id] = ZONE_EVENTS[zone_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: `zones/${zone_id.slice(0, 14)}/${zone_id.slice(0, 34)}/${zone_id}/events`,
name: `topics/${topic_id.slice(0, 14)}/${topic_id.slice(0, 34)}/${topic_id}/events`,
id_field: 'id',
organize: by_lurid,
indexers: {
@ -65,22 +65,22 @@ export function get_events_collection_for_zone(zone_id: string): FSDB_COLLECTION
eviction_timeout: 0
};
if (ZONE_EVENTS[zone_id].eviction_timeout) {
clearTimeout(ZONE_EVENTS[zone_id].eviction_timeout);
if (TOPIC_EVENTS[topic_id].eviction_timeout) {
clearTimeout(TOPIC_EVENTS[topic_id].eviction_timeout);
}
ZONE_EVENTS[zone_id].eviction_timeout = setTimeout(() => {
delete ZONE_EVENTS[zone_id];
TOPIC_EVENTS[topic_id].eviction_timeout = setTimeout(() => {
delete TOPIC_EVENTS[topic_id];
}, 60_000 * 5);
return ZONE_EVENTS[zone_id].collection;
return TOPIC_EVENTS[topic_id].collection;
}
export function clear_zone_events_cache() {
for (const [zone_id, cached] of Object.entries(ZONE_EVENTS)) {
export function clear_topic_events_cache() {
for (const [topic_id, cached] of Object.entries(TOPIC_EVENTS)) {
if (cached.eviction_timeout) {
clearTimeout(cached.eviction_timeout);
}
delete ZONE_EVENTS[zone_id];
delete TOPIC_EVENTS[topic_id];
}
}