This commit is contained in:
Martti Malmi
2024-01-18 16:40:01 +02:00
parent d019544053
commit e3f8d48ddb
2 changed files with 5 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import { ID, ReqFilter as Filter, STR, TaggedNostrEvent, UID } from ".";
import loki from "lokijs";
import debug from "debug";
type PackedNostrEvent = {
id: UID;
@ -38,6 +39,8 @@ class InMemoryDB {
setTimeout(() => removeOldest(), 3000);
}
#log = debug("InMemoryDB");
get(id: string): TaggedNostrEvent | undefined {
const event = this.eventsCollection.by("id", ID(id)); // throw if db not ready yet?
if (event) {
@ -120,9 +123,9 @@ class InMemoryDB {
removeOldest(): void {
const count = this.eventsCollection.count();
console.log("InMemoryDB: count", count, this.maxSize);
this.#log("InMemoryDB: count", count, this.maxSize);
if (count > this.maxSize) {
console.log("InMemoryDB: removing oldest events", count - this.maxSize);
this.#log("InMemoryDB: removing oldest events", count - this.maxSize);
this.eventsCollection
.chain()
.simplesort("saved_at")