mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 00:16:24 +00:00
unsaved connections limit
This commit is contained in:
@@ -201,6 +201,7 @@ module.exports = {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.datastore = new JsonLinesDatabase(path.join(dir, 'connections.jsonl'));
|
this.datastore = new JsonLinesDatabase(path.join(dir, 'connections.jsonl'));
|
||||||
}
|
}
|
||||||
|
await this.checkUnsavedConnectionsLimit();
|
||||||
},
|
},
|
||||||
|
|
||||||
list_meta: true,
|
list_meta: true,
|
||||||
@@ -300,6 +301,29 @@ module.exports = {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async checkUnsavedConnectionsLimit() {
|
||||||
|
const MAX_UNSAVED_CONNECTIONS = 5;
|
||||||
|
await this.datastore.transformAll(connections => {
|
||||||
|
const count = connections.filter(x => x.unsaved).length;
|
||||||
|
if (count > MAX_UNSAVED_CONNECTIONS) {
|
||||||
|
const res = [];
|
||||||
|
let unsavedToSkip = count - MAX_UNSAVED_CONNECTIONS;
|
||||||
|
for (const item of connections) {
|
||||||
|
if (item.unsaved) {
|
||||||
|
if (unsavedToSkip > 0) {
|
||||||
|
unsavedToSkip--;
|
||||||
|
} else {
|
||||||
|
res.push(item);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
update_meta: true,
|
update_meta: true,
|
||||||
async update({ _id, values }, req) {
|
async update({ _id, values }, req) {
|
||||||
if (portalConnections) return;
|
if (portalConnections) return;
|
||||||
|
|||||||
@@ -111,6 +111,15 @@ class JsonLinesDatabase {
|
|||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async transformAll(transformFunction) {
|
||||||
|
await this._ensureLoaded();
|
||||||
|
const newData = transformFunction(this.data);
|
||||||
|
if (newData) {
|
||||||
|
this.data = newData;
|
||||||
|
await this._save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// async _openReader() {
|
// async _openReader() {
|
||||||
// return new Promise((resolve, reject) =>
|
// return new Promise((resolve, reject) =>
|
||||||
// lineReader.open(this.filename, (err, reader) => {
|
// lineReader.open(this.filename, (err, reader) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user