refactor: rooms => zones
This commit is contained in:
parent
525568d368
commit
20a5d1bc88
27 changed files with 2466 additions and 2044 deletions
|
|
@ -13,8 +13,8 @@ import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers';
|
|||
*
|
||||
* @property {string} id - lurid
|
||||
* @property {string} creator_id - id of the source user
|
||||
* @property {string} room_id - id of the target room
|
||||
* @property {string} type - event type
|
||||
* @property {string} [parent_id] - optional parent event id
|
||||
* @property {string[]} [tags] - optional event tags
|
||||
* @property {Record<string,any>} [data] - optional data payload of the event
|
||||
* @property {TIMESTAMPS} timestamps - timestamps that will be set by the server
|
||||
|
|
@ -23,6 +23,7 @@ export type EVENT = {
|
|||
id: string;
|
||||
creator_id: string;
|
||||
type: string;
|
||||
parent_id?: string;
|
||||
tags?: string[];
|
||||
data?: Record<string, any>;
|
||||
timestamps: {
|
||||
|
|
@ -31,16 +32,16 @@ export type EVENT = {
|
|||
};
|
||||
};
|
||||
|
||||
type ROOM_EVENT_CACHE_ENTRY = {
|
||||
type ZONE_EVENT_CACHE_ENTRY = {
|
||||
collection: FSDB_COLLECTION<EVENT>;
|
||||
eviction_timeout: number;
|
||||
};
|
||||
|
||||
const ROOM_EVENTS: Record<string, ROOM_EVENT_CACHE_ENTRY> = {};
|
||||
export function get_events_collection_for_room(room_id: string): FSDB_COLLECTION<EVENT> {
|
||||
ROOM_EVENTS[room_id] = ROOM_EVENTS[room_id] ?? {
|
||||
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] ?? {
|
||||
collection: new FSDB_COLLECTION<EVENT>({
|
||||
name: `rooms/${room_id.slice(0, 14)}/${room_id.slice(0, 34)}/${room_id}/events`,
|
||||
name: `zones/${zone_id.slice(0, 14)}/${zone_id.slice(0, 34)}/${zone_id}/events`,
|
||||
id_field: 'id',
|
||||
organize: by_lurid,
|
||||
indexers: {
|
||||
|
|
@ -64,22 +65,22 @@ export function get_events_collection_for_room(room_id: string): FSDB_COLLECTION
|
|||
eviction_timeout: 0
|
||||
};
|
||||
|
||||
if (ROOM_EVENTS[room_id].eviction_timeout) {
|
||||
clearTimeout(ROOM_EVENTS[room_id].eviction_timeout);
|
||||
if (ZONE_EVENTS[zone_id].eviction_timeout) {
|
||||
clearTimeout(ZONE_EVENTS[zone_id].eviction_timeout);
|
||||
}
|
||||
|
||||
ROOM_EVENTS[room_id].eviction_timeout = setTimeout(() => {
|
||||
delete ROOM_EVENTS[room_id];
|
||||
ZONE_EVENTS[zone_id].eviction_timeout = setTimeout(() => {
|
||||
delete ZONE_EVENTS[zone_id];
|
||||
}, 60_000 * 5);
|
||||
|
||||
return ROOM_EVENTS[room_id].collection;
|
||||
return ZONE_EVENTS[zone_id].collection;
|
||||
}
|
||||
|
||||
export function clear_room_events_cache() {
|
||||
for (const [room_id, cached] of Object.entries(ROOM_EVENTS)) {
|
||||
export function clear_zone_events_cache() {
|
||||
for (const [zone_id, cached] of Object.entries(ZONE_EVENTS)) {
|
||||
if (cached.eviction_timeout) {
|
||||
clearTimeout(cached.eviction_timeout);
|
||||
}
|
||||
delete ROOM_EVENTS[room_id];
|
||||
delete ZONE_EVENTS[zone_id];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue