From 0833aa3b30ac188a86139c7303412689ed79ce96 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Sun, 29 Aug 2021 00:52:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0nedb=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E6=AF=94=E5=AF=B9=EF=BC=8C=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=AF=B9db=E6=96=87=E4=BB=B6=E4=B8=8D=E6=96=AD=E5=A2=9E?= =?UTF-8?q?=E5=A4=A7=E7=9A=84=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cron.ts | 1 + back/services/env.ts | 33 +++++++++++++++------------------ back/services/open.ts | 1 + 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/back/services/cron.ts b/back/services/cron.ts index 0a2a966f..3bce672e 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -23,6 +23,7 @@ export default class CronService { this.cronDb.loadDatabase((err) => { if (err) throw err; }); + this.cronDb.persistence.setAutocompactionInterval(30000); } public getDb(): DataStore { diff --git a/back/services/env.ts b/back/services/env.ts index 72eb1e8f..1a4f1227 100644 --- a/back/services/env.ts +++ b/back/services/env.ts @@ -9,11 +9,12 @@ import _ from 'lodash'; @Service() export default class EnvService { - private cronDb = new DataStore({ filename: config.envDbFile }); + private envDb = new DataStore({ filename: config.envDbFile }); constructor(@Inject('logger') private logger: winston.Logger) { - this.cronDb.loadDatabase((err) => { + this.envDb.loadDatabase((err) => { if (err) throw err; }); + this.envDb.persistence.setAutocompactionInterval(30000); } public async create(payloads: Env[]): Promise { @@ -34,7 +35,7 @@ export default class EnvService { public async insert(payloads: Env[]): Promise { return new Promise((resolve) => { - this.cronDb.insert(payloads, (err, docs) => { + this.envDb.insert(payloads, (err, docs) => { if (err) { this.logger.error(err); } else { @@ -55,7 +56,7 @@ export default class EnvService { private async updateDb(payload: Env): Promise { return new Promise((resolve) => { - this.cronDb.update( + this.envDb.update( { _id: payload._id }, payload, { returnUpdatedDocs: true }, @@ -72,14 +73,10 @@ export default class EnvService { public async remove(ids: string[]) { return new Promise((resolve: any) => { - this.cronDb.remove( - { _id: { $in: ids } }, - { multi: true }, - async (err) => { - await this.set_envs(); - resolve(); - }, - ); + this.envDb.remove({ _id: { $in: ids } }, { multi: true }, async (err) => { + await this.set_envs(); + resolve(); + }); }); } @@ -140,7 +137,7 @@ export default class EnvService { private async find(query: any, sort: any): Promise { return new Promise((resolve) => { - this.cronDb + this.envDb .find(query) .sort({ ...sort }) .exec((err, docs) => { @@ -151,7 +148,7 @@ export default class EnvService { public async get(_id: string): Promise { return new Promise((resolve) => { - this.cronDb.find({ _id }).exec((err, docs) => { + this.envDb.find({ _id }).exec((err, docs) => { resolve(docs[0]); }); }); @@ -159,7 +156,7 @@ export default class EnvService { public async getBySort(sort: any): Promise { return new Promise((resolve) => { - this.cronDb + this.envDb .find({}) .sort({ ...sort }) .limit(1) @@ -171,7 +168,7 @@ export default class EnvService { public async disabled(ids: string[]) { return new Promise((resolve: any) => { - this.cronDb.update( + this.envDb.update( { _id: { $in: ids } }, { $set: { status: EnvStatus.disabled } }, { multi: true }, @@ -185,7 +182,7 @@ export default class EnvService { public async enabled(ids: string[]) { return new Promise((resolve: any) => { - this.cronDb.update( + this.envDb.update( { _id: { $in: ids } }, { $set: { status: EnvStatus.normal } }, { multi: true }, @@ -199,7 +196,7 @@ export default class EnvService { public async updateNames({ ids, name }: { ids: string[]; name: string }) { return new Promise((resolve: any) => { - this.cronDb.update( + this.envDb.update( { _id: { $in: ids } }, { $set: { name } }, { multi: true }, diff --git a/back/services/open.ts b/back/services/open.ts index 17f406da..03e342f3 100644 --- a/back/services/open.ts +++ b/back/services/open.ts @@ -13,6 +13,7 @@ export default class OpenService { this.appDb.loadDatabase((err) => { if (err) throw err; }); + this.appDb.persistence.setAutocompactionInterval(30000); } public getDb(): DataStore {