1
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2024-12-24 22:14:47 +02:00

fix high memory usage

This commit is contained in:
LouisLam 2021-08-22 02:07:10 +08:00
parent ca3b0a0f19
commit 05680472a7

View File

@ -1,5 +1,5 @@
const fs = require("fs"); const fs = require("fs");
const { sleep } = require("../src/util"); const { sleep, debug, isDev } = require("../src/util");
const { R } = require("redbean-node"); const { R } = require("redbean-node");
const { setSetting, setting } = require("./util-server"); const { setSetting, setting } = require("./util-server");
const knex = require("knex"); const knex = require("knex");
@ -23,20 +23,37 @@ class Database {
const Dialect = require("knex/lib/dialects/sqlite3/index.js"); const Dialect = require("knex/lib/dialects/sqlite3/index.js");
Dialect.prototype._driver = () => sqlite3; Dialect.prototype._driver = () => sqlite3;
// Disable Pool by overriding acquireConnection() if (isDev) {
Dialect.prototype.acquireConnection = async () => { Dialect.prototype.acquireConnectionOrg = Dialect.prototype.acquireConnection;
return this.sqliteInstance;
Dialect.prototype.acquireConnection = async function () {
let a = await this.acquireConnectionOrg();
debug("acquired Connection");
return a;
};
} }
Dialect.prototype.releaseConnection = async () => { }
// Always return same connection.
Dialect.prototype.acquireRawConnection = async function () {
return Database.sqliteInstance;
};
Dialect.prototype.destroyRawConnection = async () => { }
const knexInstance = knex({ const knexInstance = knex({
client: Dialect, client: Dialect,
connection: { connection: { }, // Do not remove, Leave it empty is ok
filename: Database.path,
},
useNullAsDefault: true, useNullAsDefault: true,
pool: {
min: 1,
max: 5,
idleTimeoutMillis: 30000,
}
}); });
console.log( knexInstance.pool)
console.log("pool size")
R.setup(knexInstance); R.setup(knexInstance);
if (process.env.SQL_LOG === "1") { if (process.env.SQL_LOG === "1") {