mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
better types & use attend instead of enroll
This commit is contained in:
1 parent
e7428c8f79
commit
3dd4c1c994
17 files changed
+141
-82
No files matched your search
@@ -2,11 +2,11 @@ import Lru from 'lru-cache';
|
||||
import * as db from '../service/db';
|
||||
|
||||
const coll = db.collection('system');
|
||||
const cache = new Lru({
|
||||
const cache = new Lru<string, string | number>({
|
||||
maxAge: 5000,
|
||||
});
|
||||
|
||||
export async function get(_id: string) {
|
||||
export async function get(_id: string): Promise<string | number> {
|
||||
const res = cache.get(_id);
|
||||
if (res !== undefined) return res;
|
||||
const doc = await coll.findOne({ _id });
|
||||
@@ -51,11 +51,13 @@ export async function set(_id: string, value: any) {
|
||||
export async function inc(_id: string) {
|
||||
const res = await coll.findOneAndUpdate(
|
||||
{ _id },
|
||||
// FIXME NumberKeys<>
|
||||
// @ts-ignore
|
||||
{ $inc: { value: 1 } },
|
||||
{ upsert: true, returnOriginal: false },
|
||||
);
|
||||
cache.set(_id, res.value.value);
|
||||
return res.value.value;
|
||||
return res.value.value as number;
|
||||
}
|
||||
|
||||
global.Hydro.model.system = {
|
||||
|
||||
Reference in new issue
Block a user