Move locks to their own DB collection

This commit is contained in:
Divya Jagadish authored and Zaid Humaimidi committed 2023-10-08 12:14:06 -07:00
1 parent c3954c277f
commit 02665faa9f
6 files changed
+61 -46

No files matched your search

+3
View File
@@ -37,6 +37,7 @@ export const collections = {
users: null as Collection<MongoTypes.User>,
config: null as Collection<MongoTypes.Config>,
cache: null as Collection<MongoTypes.Cache>,
locks: null as Collection<MongoTypes.Lock>,
};
let clientPromise: Promise<MongoClient>;
@@ -60,11 +61,13 @@ export async function connect(): Promise<void> {
collections.users = db.collection("users");
collections.config = db.collection("config");
collections.cache = db.collection("cache");
collections.locks = db.collection("locks");
filesBucket = new GridFSBucket(db);
await Promise.all([
collections.tasks.createIndex({ device: 1, timestamp: 1 }),
collections.cache.createIndex({ expire: 1 }, { expireAfterSeconds: 0 }),
collections.locks.createIndex({ expire: 1 }, { expireAfterSeconds: 0 }),
]);
}
+7
View File
@@ -173,3 +173,10 @@ export interface User {
roles: string;
salt: string;
}
export interface Lock {
_id: string;
value: string;
timestamp: Date;
expire: Date;
}