feat: cache the operator ID
This commit is contained in:
parent
6d9304ca14
commit
0f3df7f12c
1 changed files with 7 additions and 1 deletions
|
|
@ -1,8 +1,14 @@
|
||||||
const db = require('./db')
|
const db = require('./db')
|
||||||
|
|
||||||
|
let operatorId = {}
|
||||||
|
|
||||||
function getOperatorId(service) {
|
function getOperatorId(service) {
|
||||||
|
if (operatorId[service]) return Promise.resolve(operatorId[service])
|
||||||
|
|
||||||
const sql = 'SELECT operator_id FROM operator_ids WHERE service = ${service}'
|
const sql = 'SELECT operator_id FROM operator_ids WHERE service = ${service}'
|
||||||
return db.oneOrNone(sql, { service }, ({ operator_id }) => operator_id)
|
return db.one(sql, { service }, ({ operator_id }) => {
|
||||||
|
return (operatorId[service] = operator_id)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { getOperatorId }
|
module.exports = { getOperatorId }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue