mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 21:59:00 +02:00
5fb275392f
Decaf cleanup: unnecessary returns GitOrigin-RevId: e3c006b0e15095c8cbed2911269f704a7fdd1d57
69 lines
1.6 KiB
JavaScript
69 lines
1.6 KiB
JavaScript
/* eslint-disable
|
|
n/handle-callback-err,
|
|
*/
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
// Fix any style issues and re-enable lint.
|
|
/*
|
|
* decaffeinate suggestions:
|
|
* DS207: Consider shorter variations of null checks
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
*/
|
|
let SystemMessageManager
|
|
const { SystemMessage } = require('../../models/SystemMessage')
|
|
const {
|
|
addRequiredCleanupHandlerBeforeDrainingConnections,
|
|
} = require('../../infrastructure/GracefulShutdown')
|
|
|
|
module.exports = SystemMessageManager = {
|
|
getMessages(callback) {
|
|
if (callback == null) {
|
|
callback = function () {}
|
|
}
|
|
callback(null, this._cachedMessages)
|
|
},
|
|
|
|
getMessagesFromDB(callback) {
|
|
if (callback == null) {
|
|
callback = function () {}
|
|
}
|
|
SystemMessage.find({}, callback)
|
|
},
|
|
|
|
clearMessages(callback) {
|
|
if (callback == null) {
|
|
callback = function () {}
|
|
}
|
|
SystemMessage.deleteMany({}, callback)
|
|
},
|
|
|
|
createMessage(content, callback) {
|
|
if (callback == null) {
|
|
callback = function () {}
|
|
}
|
|
const message = new SystemMessage({ content })
|
|
message.save(callback)
|
|
},
|
|
|
|
refreshCache() {
|
|
this.getMessagesFromDB((error, messages) => {
|
|
if (!error) {
|
|
this._cachedMessages = messages
|
|
}
|
|
})
|
|
},
|
|
}
|
|
|
|
const CACHE_TIMEOUT = 10 * 1000 * (Math.random() + 2) // 20-30 seconds
|
|
SystemMessageManager.refreshCache()
|
|
const intervalHandle = setInterval(
|
|
() => SystemMessageManager.refreshCache(),
|
|
CACHE_TIMEOUT
|
|
)
|
|
|
|
addRequiredCleanupHandlerBeforeDrainingConnections(
|
|
'update system messages',
|
|
() => {
|
|
clearInterval(intervalHandle)
|
|
}
|
|
)
|