Skip to content
Snippets Groups Projects
Commit da53ac8d authored by Jure's avatar Jure
Browse files

Merge branch 'polling-sync' into 'master'

fix: sync cache added

See merge request !436
parents 491880f7 6989dd6f
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ const config = require('config')
const logger = require('@pubsweet/logger')
const lockedFragments = {}
let lockedFragments = {}
const initCache = async Fragment => {
const allFragments = await Fragment.all()
for (let i = 0; i < allFragments.length; i += 1) {
......@@ -12,6 +12,21 @@ const initCache = async Fragment => {
lockedFragments[id] = currentFragment.lock.editor.userId
}
}
setInterval(() => cacheSync(Fragment), 8000)
}
const cacheSync = async Fragment => {
logger.info(`Syncing cache`)
const syncedLockedFragments = {}
const allFragments = await Fragment.all()
for (let i = 0; i < allFragments.length; i += 1) {
const currentFragment = allFragments[i]
if (currentFragment.lock && currentFragment.lock !== null) {
const { id } = currentFragment
syncedLockedFragments[id] = currentFragment.lock.editor.userId
}
}
lockedFragments = syncedLockedFragments
}
const PollingServer = app => {
......@@ -119,6 +134,7 @@ const PollingServer = app => {
async (req, res, next) => {
const { collectionId, fragmentId } = req.params
const { username } = req.query
logger.info(
`Initiating polling for fragment with id ${fragmentId} of the collection with id ${collectionId} for user ${username}`,
)
......@@ -208,11 +224,10 @@ const PollingServer = app => {
res.sendStatus(403)
}
}
logger.info(`Setting timmer for ${pollingTime} ms`)
setTimer(unlocker, pollingTime, opts)
res.sendStatus(200)
}
logger.info(`Setting timmer for ${pollingTime} ms`)
setTimer(unlocker, pollingTime, opts)
res.sendStatus(200)
}
} catch (e) {
logger.error(`In polling endpoint ${e}`)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment