Repository: louislam/uptime-kuma
File: server/database.js (JavaScript)

Code before:
        mysql2.prototype.columnCompiler = function () {
            return new KumaColumnCompiler(this, ...arguments);
        };

        const acquireConnectionTimeout = 120 * 1000;
        let dbConfig;
        try {
            dbConfig = this.readDBConfig();
            Database.dbConfig = dbConfig;
        } catch (err) {
            log.warn("db", err.message);
            dbConfig = {
                type: "sqlite",
            };
        }

        let config = {};

        const DEFAULT_MAX_POOL_CONNECTIONS = 10;
        const maxPoolConnections = process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS;
        let parsedMaxPoolConnections = parseInt(maxPoolConnections);

        if (
            !maxPoolConnections ||
            maxPoolConnections.trim() === "" ||
            Number.isNaN(parsedMaxPoolConnections) ||
            parsedMaxPoolConnections > 100 ||
            // NOTE: We cap the pool size because MySQL/MariaDB connections are heavy.
            // Each connection consumes memory and CPU, and too many cause severe slowdown.
            // If you need higher concurrency, use a proxy like ProxySQL or MaxScale instead of raising this limit.
            parsedMaxPoolConnections < 1
        ) {
            parsedMaxPoolConnections = DEFAULT_MAX_POOL_CONNECTIONS;

            // Only log if there was a UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS defined
            if (maxPoolConnections !== undefined) {
                log.warn("db", `Max pool connections defaulted to ${DEFAULT_MAX_POOL_CONNECTIONS} because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was invalid`);
            }
        }

        let mariadbPoolConfig = {
            min: 0,
            max: parsedMaxPoolConnections,
            idleTimeoutMillis: 30000,
        };

        log.info("db", `Database Type: ${dbConfig.type}`);

        if (dbConfig.type === "sqlite") {

            if (! fs.existsSync(Database.sqlitePath)) {

Review comment (suggestion):
Same meaning as below I think.

```suggestion
            Number.isNaN(parsedMaxPoolConnections) ||
```

Code after:
        mysql2.prototype.columnCompiler = function () {
            return new KumaColumnCompiler(this, ...arguments);
        };

        const acquireConnectionTimeout = 120 * 1000;
        let dbConfig;
        try {
            dbConfig = this.readDBConfig();
            Database.dbConfig = dbConfig;
        } catch (err) {
            log.warn("db", err.message);
            dbConfig = {
                type: "sqlite",
            };
        }

        let config = {};

        let parsedMaxPoolConnections = parseInt(process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS);

        if (!process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS) {
            parsedMaxPoolConnections = 10;
        } else if (Number.isNaN(parsedMaxPoolConnections)) {
            log.warn("db", "Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was invalid.");
            parsedMaxPoolConnections = 10;
        } else if (parsedMaxPoolConnections < 1) {
            log.warn("db", "Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was less than 1.");
            parsedMaxPoolConnections = 10;
        } else if (parsedMaxPoolConnections > 100) {
            log.warn("db", "Max database connections capped to 100 because Mysql/Mariadb connections are heavy. consider using a proxy like ProxySQL or MaxScale.");
            parsedMaxPoolConnections = 100;
        }

        let mariadbPoolConfig = {
            min: 0,
            max: parsedMaxPoolConnections,
            idleTimeoutMillis: 30000,
        };

        log.info("db", `Database Type: ${dbConfig.type}`);

        if (dbConfig.type === "sqlite") {

            if (! fs.existsSync(Database.sqlitePath)) {
                log.info("server", "Copying Database");
                fs.copyFileSync(Database.templatePath, Database.sqlitePath);
            }

            const Dialect = require("knex/lib/dialects/sqlite3/index.js");
            Dialect.prototype._driver = () => require("@louislam/sqlite3");