refactor: remove unnecessary query parameters

This commit is contained in:
siiky 2024-09-17 14:57:30 +01:00
parent 3a548fea6f
commit 437a1d3505

View file

@ -161,13 +161,13 @@ function loadLatest (schemaVersion) {
function loadLatestConfig () {
const sql = `SELECT data
FROM user_config
WHERE type = $1
AND schema_version = $2
WHERE type = 'config'
AND schema_version = $1
AND valid
ORDER BY id DESC
LIMIT 1`
return db.one(sql, ['config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.one(sql, [NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => row ? row.data.config : {})
.catch(err => {
throw err
@ -177,24 +177,25 @@ function loadLatestConfig () {
function loadLatestConfigOrNoneReturningVersion (schemaVersion) {
const sql = `SELECT data, id
FROM user_config
WHERE type = $1
AND schema_version = $2
WHERE type = 'config'
AND schema_version = $1
AND valid
ORDER BY id DESC
LIMIT 1`
return db.oneOrNone(sql, ['config', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.oneOrNone(sql, [schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => row ? { config: row.data.config, version: row.id } : {})
}
function loadLatestConfigOrNone (schemaVersion) {
const sql = `SELECT data
FROM user_config
WHERE type = $1
AND schema_version = $2
WHERE type = 'config'
AND schema_version = $1
ORDER BY id DESC
LIMIT 1`
return db.oneOrNone(sql, ['config', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.oneOrNone(sql, [schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => row ? row.data.config : {})
}
@ -202,11 +203,11 @@ function loadConfig (versionId) {
const sql = `SELECT data
FROM user_config
WHERE id = $1
AND type = $2
AND schema_version = $3
AND type = 'config'
AND schema_version = $2
AND valid`
return db.one(sql, [versionId, 'config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.one(sql, [versionId, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => row.data.config)
.catch(err => {
if (err.name === 'QueryResultError') {