Browse Source

Add option for database cache size

pull/6/head
Menci 6 years ago
parent
commit
e946b931c9
  1. 3
      config-example.json
  2. 4
      models/common.ts
  3. 4
      models/problem.ts

3
config-example.json

@ -7,7 +7,8 @@
"username": "syzoj", "username": "syzoj",
"password": "@DATABASE_PASSWORD@", "password": "@DATABASE_PASSWORD@",
"host": "127.0.0.1", "host": "127.0.0.1",
"migrated_to_typeorm": true "migrated_to_typeorm": true,
"cache_size": 1000
}, },
"logo": { "logo": {
"url": null, "url": null,

4
models/common.ts

@ -2,6 +2,8 @@ import * as TypeORM from "typeorm";
import * as LRUCache from "lru-cache"; import * as LRUCache from "lru-cache";
import * as DeepCopy from "deepcopy"; import * as DeepCopy from "deepcopy";
declare var syzoj: any;
interface Paginater { interface Paginater {
pageCnt: number; pageCnt: number;
perPage: number; perPage: number;
@ -23,7 +25,7 @@ const caches: Map<string, LRUCache<number, Model>> = new Map();
function ensureCache(modelName) { function ensureCache(modelName) {
if (!caches.has(modelName)) { if (!caches.has(modelName)) {
caches.set(modelName, new LRUCache({ caches.set(modelName, new LRUCache({
max: 500 max: syzoj.config.db.cache_size
})); }));
} }

4
models/problem.ts

@ -194,7 +194,9 @@ import * as util from "util";
import * as LRUCache from "lru-cache"; import * as LRUCache from "lru-cache";
import * as DeepCopy from "deepcopy"; import * as DeepCopy from "deepcopy";
const problemTagCache = new LRUCache<number, number[]>(); const problemTagCache = new LRUCache<number, number[]>({
max: syzoj.config.db.cache_size
});
enum ProblemType { enum ProblemType {
Traditional = "traditional", Traditional = "traditional",

Loading…
Cancel
Save