chore: remove db $ instances
fix: add compute-schema file fix: to_timestamp() psql usage chore: rephrase expired session deletion
This commit is contained in:
parent
2e45098033
commit
0272dc2bd1
3 changed files with 13 additions and 3 deletions
10
lib/compute-schema.js
Normal file
10
lib/compute-schema.js
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
const { asyncLocalStorage, defaultStore } = require('./async-storage')
|
||||||
|
|
||||||
|
const computeSchema = (req, res, next) => {
|
||||||
|
const store = defaultStore()
|
||||||
|
asyncLocalStorage.run(store, () => {
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = computeSchema
|
||||||
|
|
@ -11,8 +11,8 @@ const cleanUserSessions = (cleanInterval) => (req, res, next) => {
|
||||||
if (!schema) return next()
|
if (!schema) return next()
|
||||||
if (schema && schemaCache.schema + cleanInterval > now) return next()
|
if (schema && schemaCache.schema + cleanInterval > now) return next()
|
||||||
|
|
||||||
console.log('Clearing old sessions for schema', schema)
|
console.log('Clearing expired sessions for schema', schema)
|
||||||
return db.$none('DELETE FROM $1^ WHERE expire < to_timestamp($2)', [USER_SESSIONS_TABLE_NAME, now])
|
return db.none('DELETE FROM $1^ WHERE expire < to_timestamp($2 / 1000.0)', [USER_SESSIONS_TABLE_NAME, now])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
schemaCache.schema = now
|
schemaCache.schema = now
|
||||||
return next()
|
return next()
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ const getSecret = () => {
|
||||||
const hostname = options.hostname
|
const hostname = options.hostname
|
||||||
|
|
||||||
const lamaDb = {
|
const lamaDb = {
|
||||||
query: (query, values, qrm) => db.$query(query, values, qrm, false)
|
query: (query, values, qrm) => db.query(query, values, qrm, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
router.use('*', session({
|
router.use('*', session({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue