From 27f17a377ac923fda8f7378005796b0dfe1c9321 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Wed, 29 Sep 2021 21:40:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=90=AF=E6=9C=8D=E5=8A=A1=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8E=8B=E7=BC=A9db?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/loaders/initData.ts | 7 ++++++- back/services/env.ts | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index 732c5d64..68a71b79 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -26,6 +26,11 @@ export default async () => { const cronService = Container.get(CronService); const envService = Container.get(EnvService); const cronDb = cronService.getDb(); + const envDb = cronService.getDb(); + + // compaction data file + cronDb.persistence.compactDatafile(); + envDb.persistence.compactDatafile(); cronDb.count({}, async (err, count) => { if (count === 0) { @@ -92,7 +97,7 @@ export default async () => { }; function randomSchedule(from: number, to: number) { - const result = []; + const result: any[] = []; const arr = [...Array(from).keys()]; let count = arr.length; for (let i = 0; i < to; i++) { diff --git a/back/services/env.ts b/back/services/env.ts index 8e9c900d..be06976e 100644 --- a/back/services/env.ts +++ b/back/services/env.ts @@ -16,11 +16,15 @@ export default class EnvService { }); } + public getDb(): DataStore { + return this.envDb; + } + public async create(payloads: Env[]): Promise { const envs = await this.envs(); let position = initEnvPosition; if (envs && envs.length > 0 && envs[envs.length - 1].position) { - position = envs[envs.length - 1].position; + position = envs[envs.length - 1].position as number; } const tabs = payloads.map((x) => { position = position / 2;