fix: objection.js 2.0 compat fixes

This commit is contained in:
NGPixel 2020-01-26 13:11:33 -05:00
parent 8f5265622f
commit da86d8ccf7
2 changed files with 10 additions and 10 deletions

View File

@ -362,16 +362,16 @@ module.exports = {
return process.cwd() return process.cwd()
}, },
async groupsTotal () { async groupsTotal () {
const total = await WIKI.models.groups.query().count('* as total').first().pluck('total') const total = await WIKI.models.groups.query().count('* as total').first()
return _.toSafeInteger(total) return _.toSafeInteger(total.total)
}, },
async pagesTotal () { async pagesTotal () {
const total = await WIKI.models.pages.query().count('* as total').first().pluck('total') const total = await WIKI.models.pages.query().count('* as total').first()
return _.toSafeInteger(total) return _.toSafeInteger(total.total)
}, },
async usersTotal () { async usersTotal () {
const total = await WIKI.models.users.query().count('* as total').first().pluck('total') const total = await WIKI.models.users.query().count('* as total').first()
return _.toSafeInteger(total) return _.toSafeInteger(total.total)
} }
} }
} }

View File

@ -570,7 +570,7 @@ module.exports = class Page extends Model {
let affectedHashes = [] let affectedHashes = []
// -> Perform replace and return affected page hashes (POSTGRES only) // -> Perform replace and return affected page hashes (POSTGRES only)
if (WIKI.config.db.type === 'postgres') { if (WIKI.config.db.type === 'postgres') {
affectedHashes = await WIKI.models.pages.query() const qryHashes = await WIKI.models.pages.query()
.returning('hash') .returning('hash')
.patch({ .patch({
render: WIKI.models.knex.raw('REPLACE(??, ?, ?)', ['render', replaceArgs.from, replaceArgs.to]) render: WIKI.models.knex.raw('REPLACE(??, ?, ?)', ['render', replaceArgs.from, replaceArgs.to])
@ -581,7 +581,7 @@ module.exports = class Page extends Model {
'pageLinks.localeCode': opts.locale 'pageLinks.localeCode': opts.locale
}) })
}) })
.pluck('hash') affectedHashes = qryHashes.map(h => h.hash)
} else { } else {
// -> Perform replace, then query affected page hashes (MYSQL, MARIADB, MSSQL, SQLITE only) // -> Perform replace, then query affected page hashes (MYSQL, MARIADB, MSSQL, SQLITE only)
await WIKI.models.pages.query() await WIKI.models.pages.query()
@ -594,7 +594,7 @@ module.exports = class Page extends Model {
'pageLinks.localeCode': opts.locale 'pageLinks.localeCode': opts.locale
}) })
}) })
affectedHashes = await WIKI.models.pages.query() const qryHashes = await WIKI.models.pages.query()
.column('hash') .column('hash')
.whereIn('pages.id', function () { .whereIn('pages.id', function () {
this.select('pageLinks.pageId').from('pageLinks').where({ this.select('pageLinks.pageId').from('pageLinks').where({
@ -602,7 +602,7 @@ module.exports = class Page extends Model {
'pageLinks.localeCode': opts.locale 'pageLinks.localeCode': opts.locale
}) })
}) })
.pluck('hash') affectedHashes = qryHashes.map(h => h.hash)
} }
for (const hash of affectedHashes) { for (const hash of affectedHashes) {
await WIKI.models.pages.deletePageFromCache({ hash }) await WIKI.models.pages.deletePageFromCache({ hash })