mirror of
https://github.com/whyour/qinglong.git
synced 2025-06-01 22:46:06 +08:00
增加nedb数据自定比对,测试对db文件不断增大的影响
This commit is contained in:
parent
9c90bbc146
commit
0833aa3b30
|
@ -23,6 +23,7 @@ export default class CronService {
|
||||||
this.cronDb.loadDatabase((err) => {
|
this.cronDb.loadDatabase((err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
});
|
});
|
||||||
|
this.cronDb.persistence.setAutocompactionInterval(30000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getDb(): DataStore {
|
public getDb(): DataStore {
|
||||||
|
|
|
@ -9,11 +9,12 @@ import _ from 'lodash';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class EnvService {
|
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) {
|
constructor(@Inject('logger') private logger: winston.Logger) {
|
||||||
this.cronDb.loadDatabase((err) => {
|
this.envDb.loadDatabase((err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
});
|
});
|
||||||
|
this.envDb.persistence.setAutocompactionInterval(30000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async create(payloads: Env[]): Promise<Env[]> {
|
public async create(payloads: Env[]): Promise<Env[]> {
|
||||||
|
@ -34,7 +35,7 @@ export default class EnvService {
|
||||||
|
|
||||||
public async insert(payloads: Env[]): Promise<Env[]> {
|
public async insert(payloads: Env[]): Promise<Env[]> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.cronDb.insert(payloads, (err, docs) => {
|
this.envDb.insert(payloads, (err, docs) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
} else {
|
} else {
|
||||||
|
@ -55,7 +56,7 @@ export default class EnvService {
|
||||||
|
|
||||||
private async updateDb(payload: Env): Promise<Env> {
|
private async updateDb(payload: Env): Promise<Env> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.cronDb.update(
|
this.envDb.update(
|
||||||
{ _id: payload._id },
|
{ _id: payload._id },
|
||||||
payload,
|
payload,
|
||||||
{ returnUpdatedDocs: true },
|
{ returnUpdatedDocs: true },
|
||||||
|
@ -72,14 +73,10 @@ export default class EnvService {
|
||||||
|
|
||||||
public async remove(ids: string[]) {
|
public async remove(ids: string[]) {
|
||||||
return new Promise((resolve: any) => {
|
return new Promise((resolve: any) => {
|
||||||
this.cronDb.remove(
|
this.envDb.remove({ _id: { $in: ids } }, { multi: true }, async (err) => {
|
||||||
{ _id: { $in: ids } },
|
|
||||||
{ multi: true },
|
|
||||||
async (err) => {
|
|
||||||
await this.set_envs();
|
await this.set_envs();
|
||||||
resolve();
|
resolve();
|
||||||
},
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +137,7 @@ export default class EnvService {
|
||||||
|
|
||||||
private async find(query: any, sort: any): Promise<Env[]> {
|
private async find(query: any, sort: any): Promise<Env[]> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.cronDb
|
this.envDb
|
||||||
.find(query)
|
.find(query)
|
||||||
.sort({ ...sort })
|
.sort({ ...sort })
|
||||||
.exec((err, docs) => {
|
.exec((err, docs) => {
|
||||||
|
@ -151,7 +148,7 @@ export default class EnvService {
|
||||||
|
|
||||||
public async get(_id: string): Promise<Env> {
|
public async get(_id: string): Promise<Env> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.cronDb.find({ _id }).exec((err, docs) => {
|
this.envDb.find({ _id }).exec((err, docs) => {
|
||||||
resolve(docs[0]);
|
resolve(docs[0]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -159,7 +156,7 @@ export default class EnvService {
|
||||||
|
|
||||||
public async getBySort(sort: any): Promise<Env> {
|
public async getBySort(sort: any): Promise<Env> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.cronDb
|
this.envDb
|
||||||
.find({})
|
.find({})
|
||||||
.sort({ ...sort })
|
.sort({ ...sort })
|
||||||
.limit(1)
|
.limit(1)
|
||||||
|
@ -171,7 +168,7 @@ export default class EnvService {
|
||||||
|
|
||||||
public async disabled(ids: string[]) {
|
public async disabled(ids: string[]) {
|
||||||
return new Promise((resolve: any) => {
|
return new Promise((resolve: any) => {
|
||||||
this.cronDb.update(
|
this.envDb.update(
|
||||||
{ _id: { $in: ids } },
|
{ _id: { $in: ids } },
|
||||||
{ $set: { status: EnvStatus.disabled } },
|
{ $set: { status: EnvStatus.disabled } },
|
||||||
{ multi: true },
|
{ multi: true },
|
||||||
|
@ -185,7 +182,7 @@ export default class EnvService {
|
||||||
|
|
||||||
public async enabled(ids: string[]) {
|
public async enabled(ids: string[]) {
|
||||||
return new Promise((resolve: any) => {
|
return new Promise((resolve: any) => {
|
||||||
this.cronDb.update(
|
this.envDb.update(
|
||||||
{ _id: { $in: ids } },
|
{ _id: { $in: ids } },
|
||||||
{ $set: { status: EnvStatus.normal } },
|
{ $set: { status: EnvStatus.normal } },
|
||||||
{ multi: true },
|
{ multi: true },
|
||||||
|
@ -199,7 +196,7 @@ export default class EnvService {
|
||||||
|
|
||||||
public async updateNames({ ids, name }: { ids: string[]; name: string }) {
|
public async updateNames({ ids, name }: { ids: string[]; name: string }) {
|
||||||
return new Promise((resolve: any) => {
|
return new Promise((resolve: any) => {
|
||||||
this.cronDb.update(
|
this.envDb.update(
|
||||||
{ _id: { $in: ids } },
|
{ _id: { $in: ids } },
|
||||||
{ $set: { name } },
|
{ $set: { name } },
|
||||||
{ multi: true },
|
{ multi: true },
|
||||||
|
|
|
@ -13,6 +13,7 @@ export default class OpenService {
|
||||||
this.appDb.loadDatabase((err) => {
|
this.appDb.loadDatabase((err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
});
|
});
|
||||||
|
this.appDb.persistence.setAutocompactionInterval(30000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getDb(): DataStore {
|
public getDb(): DataStore {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user