From e946b931c9fc34e72374bc8624b7426c003edc5a Mon Sep 17 00:00:00 2001 From: Menci Date: Mon, 22 Apr 2019 09:29:51 +0800 Subject: [PATCH] Add option for database cache size --- config-example.json | 3 ++- models/common.ts | 4 +++- models/problem.ts | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config-example.json b/config-example.json index 7f7b596..3e92f90 100644 --- a/config-example.json +++ b/config-example.json @@ -7,7 +7,8 @@ "username": "syzoj", "password": "@DATABASE_PASSWORD@", "host": "127.0.0.1", - "migrated_to_typeorm": true + "migrated_to_typeorm": true, + "cache_size": 1000 }, "logo": { "url": null, diff --git a/models/common.ts b/models/common.ts index 198324d..e533051 100644 --- a/models/common.ts +++ b/models/common.ts @@ -2,6 +2,8 @@ import * as TypeORM from "typeorm"; import * as LRUCache from "lru-cache"; import * as DeepCopy from "deepcopy"; +declare var syzoj: any; + interface Paginater { pageCnt: number; perPage: number; @@ -23,7 +25,7 @@ const caches: Map> = new Map(); function ensureCache(modelName) { if (!caches.has(modelName)) { caches.set(modelName, new LRUCache({ - max: 500 + max: syzoj.config.db.cache_size })); } diff --git a/models/problem.ts b/models/problem.ts index 0bd0d1f..89f3587 100644 --- a/models/problem.ts +++ b/models/problem.ts @@ -194,7 +194,9 @@ import * as util from "util"; import * as LRUCache from "lru-cache"; import * as DeepCopy from "deepcopy"; -const problemTagCache = new LRUCache(); +const problemTagCache = new LRUCache({ + max: syzoj.config.db.cache_size +}); enum ProblemType { Traditional = "traditional",