From b1524d245e193d4803215145c7fac1dad673a823 Mon Sep 17 00:00:00 2001 From: Selfhost Alt Date: Thu, 14 Sep 2023 22:52:43 -0700 Subject: [PATCH 1/5] Add ability to enable DEV logs of Sqlite queries --- server/Database.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/Database.js b/server/Database.js index a959d0a9..09f6dfc7 100644 --- a/server/Database.js +++ b/server/Database.js @@ -166,10 +166,25 @@ class Database { */ async connect() { Logger.info(`[Database] Initializing db at "${this.dbPath}"`) + + let logging = false; + let benchmark = false; + if (process.env.QUERY_LOGGING === "log") { + // Setting QUERY_LOGGING=log will log all Sequelize queries before they run + Logger.info(`[Database] Query logging enabled"`) + logging = (query) => Logger.dev(`Running the following query: ${query}`) + } else if (process.env.QUERY_LOGGING === "benchmark") { + // Setting QUERY_LOGGING=benchmark will log all Sequelize queries and their execution times, after they run + Logger.info(`[Database] Query benchmarking enabled"`) + logging = (query, time) => Logger.dev(`Ran the following query in ${time}ms: ${query}`) + benchmark = true; + } + this.sequelize = new Sequelize({ dialect: 'sqlite', storage: this.dbPath, - logging: false, + logging: logging, + benchmark: benchmark, transactionType: 'IMMEDIATE' }) From 71762ef8371c45b8cb9a61f09c12ea531743c632 Mon Sep 17 00:00:00 2001 From: Selfhost Alt Date: Thu, 14 Sep 2023 23:01:40 -0700 Subject: [PATCH 2/5] Newline before printing query --- server/Database.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/Database.js b/server/Database.js index 09f6dfc7..1d7ae9ab 100644 --- a/server/Database.js +++ b/server/Database.js @@ -172,11 +172,11 @@ class Database { if (process.env.QUERY_LOGGING === "log") { // Setting QUERY_LOGGING=log will log all Sequelize queries before they run Logger.info(`[Database] Query logging enabled"`) - logging = (query) => Logger.dev(`Running the following query: ${query}`) + logging = (query) => Logger.dev(`Running the following query:\n ${query}`) } else if (process.env.QUERY_LOGGING === "benchmark") { // Setting QUERY_LOGGING=benchmark will log all Sequelize queries and their execution times, after they run Logger.info(`[Database] Query benchmarking enabled"`) - logging = (query, time) => Logger.dev(`Ran the following query in ${time}ms: ${query}`) + logging = (query, time) => Logger.dev(`Ran the following query in ${time}ms:\n ${query}`) benchmark = true; } From b668c6e37a2bf62784a7ba6ca17c15ab3511104a Mon Sep 17 00:00:00 2001 From: Selfhost Alt Date: Thu, 14 Sep 2023 23:04:47 -0700 Subject: [PATCH 3/5] Remove stray quote --- server/Database.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Database.js b/server/Database.js index 1d7ae9ab..82cda3fc 100644 --- a/server/Database.js +++ b/server/Database.js @@ -171,7 +171,7 @@ class Database { let benchmark = false; if (process.env.QUERY_LOGGING === "log") { // Setting QUERY_LOGGING=log will log all Sequelize queries before they run - Logger.info(`[Database] Query logging enabled"`) + Logger.info(`[Database] Query logging enabled`) logging = (query) => Logger.dev(`Running the following query:\n ${query}`) } else if (process.env.QUERY_LOGGING === "benchmark") { // Setting QUERY_LOGGING=benchmark will log all Sequelize queries and their execution times, after they run From b64ecc7c6fab4cfa6d6770433b8f9d744e71e64c Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 22 Sep 2023 16:14:00 -0500 Subject: [PATCH 4/5] Update server/Database.js --- server/Database.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Database.js b/server/Database.js index 82cda3fc..b6823ce5 100644 --- a/server/Database.js +++ b/server/Database.js @@ -177,7 +177,7 @@ class Database { // Setting QUERY_LOGGING=benchmark will log all Sequelize queries and their execution times, after they run Logger.info(`[Database] Query benchmarking enabled"`) logging = (query, time) => Logger.dev(`Ran the following query in ${time}ms:\n ${query}`) - benchmark = true; + benchmark = true } this.sequelize = new Sequelize({ From 1ab34fa77f0b6b93599c39129f4e893672981b7a Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 22 Sep 2023 16:14:12 -0500 Subject: [PATCH 5/5] Update server/Database.js --- server/Database.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/Database.js b/server/Database.js index b6823ce5..f56de5ba 100644 --- a/server/Database.js +++ b/server/Database.js @@ -167,8 +167,8 @@ class Database { async connect() { Logger.info(`[Database] Initializing db at "${this.dbPath}"`) - let logging = false; - let benchmark = false; + let logging = false + let benchmark = false if (process.env.QUERY_LOGGING === "log") { // Setting QUERY_LOGGING=log will log all Sequelize queries before they run Logger.info(`[Database] Query logging enabled`)