mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: 性能优化
This commit is contained in:
1 parent
34465ba80a
commit
ee4dc90cf3
6 files changed
+11
-43
No files matched your search
@@ -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 };
|
||||
|
||||
Reference in new issue
Block a user