core: 性能优化

This commit is contained in:
undefined committed 2021-03-27 19:12:24 +08:00
1 parent 34465ba80a
commit ee4dc90cf3
6 files changed
+11 -43

No files matched your search

-17
View File
@@ -2,8 +2,6 @@ import fs from 'fs';
import { Duplex } from 'stream';
import cluster from 'cluster';
import path, { sep } from 'path';
import serialize from 'serialize-javascript';
import Lru from 'lru-cache';
import { ObjectID } from 'mongodb';
import { isMoment } from 'moment';
import type { Moment } from 'moment-timezone';
@@ -29,21 +27,6 @@ declare global {
}
}
const lru = new Lru(1000);
export function lrucache(target: any, funcName: string, obj: any) {
const originalMethod = obj.value;
obj.value = function func(...args: any[]) {
const key = serialize({ funcName, args });
let val = lru.get(key);
if (val) return val;
val = originalMethod.call(this, ...args);
lru.set(key, val);
return val;
};
return obj;
}
if (!cluster.worker) {
// @ts-ignore
cluster.worker = { id: 0 };