mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add db queue file for global db query queues
This commit is contained in:
parent
1080c2c428
commit
759988401b
3 changed files with 46 additions and 31 deletions
13
services/clsi/app/coffee/DbQueue.coffee
Normal file
13
services/clsi/app/coffee/DbQueue.coffee
Normal file
|
@ -0,0 +1,13 @@
|
|||
async = require "async"
|
||||
|
||||
queue = async.queue((task, cb)->
|
||||
console.log("running task")
|
||||
task(cb)
|
||||
, 1)
|
||||
|
||||
queue.drain = ()->
|
||||
console.log('HI all items have been processed')
|
||||
|
||||
module.exports =
|
||||
queue: queue
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
UrlCache = require "./UrlCache"
|
||||
CompileManager = require "./CompileManager"
|
||||
db = require "./db"
|
||||
dbQueue = require "./DbQueue"
|
||||
async = require "async"
|
||||
logger = require "logger-sharelatex"
|
||||
oneDay = 24 * 60 * 60 * 1000
|
||||
|
@ -11,15 +12,18 @@ module.exports = ProjectPersistenceManager =
|
|||
EXPIRY_TIMEOUT: Settings.project_cache_length_ms || oneDay * 2.5
|
||||
|
||||
markProjectAsJustAccessed: (project_id, callback = (error) ->) ->
|
||||
console.log("markProjectAsJustAccessed")
|
||||
db.Project.findOrCreate(where: {project_id: project_id})
|
||||
.spread(
|
||||
(project, created) ->
|
||||
project.updateAttributes(lastAccessed: new Date())
|
||||
.then(() -> callback())
|
||||
.error callback
|
||||
)
|
||||
.error callback
|
||||
job = (cb)->
|
||||
console.log("markProjectAsJustAccessed")
|
||||
db.Project.findOrCreate(where: {project_id: project_id})
|
||||
.spread(
|
||||
(project, created) ->
|
||||
project.updateAttributes(lastAccessed: new Date())
|
||||
.then(() -> cb())
|
||||
.error cb
|
||||
)
|
||||
.error cb
|
||||
dbQueue.queue.push(job, callback)
|
||||
|
||||
|
||||
clearExpiredProjects: (callback = (error) ->) ->
|
||||
ProjectPersistenceManager._findExpiredProjectIds (error, project_ids) ->
|
||||
|
@ -54,16 +58,22 @@ module.exports = ProjectPersistenceManager =
|
|||
callback()
|
||||
|
||||
_clearProjectFromDatabase: (project_id, callback = (error) ->) ->
|
||||
console.log("_clearProjectFromDatabase")
|
||||
db.Project.destroy(where: {project_id: project_id})
|
||||
.then(() -> callback())
|
||||
.error callback
|
||||
job = (cb)->
|
||||
console.log("_clearProjectFromDatabase")
|
||||
db.Project.destroy(where: {project_id: project_id})
|
||||
.then(() -> callback())
|
||||
.error callback
|
||||
dbQueue.queue.push(job, callback)
|
||||
|
||||
|
||||
_findExpiredProjectIds: (callback = (error, project_ids) ->) ->
|
||||
console.log("_findExpiredProjectIds")
|
||||
db.Project.findAll(where: ["lastAccessed < ?", new Date(Date.now() - ProjectPersistenceManager.EXPIRY_TIMEOUT)])
|
||||
.then((projects) ->
|
||||
callback null, projects.map((project) -> project.project_id)
|
||||
).error callback
|
||||
job = (cb)->
|
||||
console.log("_findExpiredProjectIds")
|
||||
db.Project.findAll(where: ["lastAccessed < ?", new Date(Date.now() - ProjectPersistenceManager.EXPIRY_TIMEOUT)])
|
||||
.then((projects) ->
|
||||
callback null, projects.map((project) -> project.project_id)
|
||||
).error callback
|
||||
dbQueue.queue.push(job, callback)
|
||||
|
||||
|
||||
logger.log {EXPIRY_TIMEOUT: ProjectPersistenceManager.EXPIRY_TIMEOUT}, "project assets kept timeout"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
db = require("./db")
|
||||
dbQueue = require "./DbQueue"
|
||||
UrlFetcher = require("./UrlFetcher")
|
||||
Settings = require("settings-sharelatex")
|
||||
crypto = require("crypto")
|
||||
|
@ -6,15 +7,6 @@ fs = require("fs")
|
|||
logger = require "logger-sharelatex"
|
||||
async = require "async"
|
||||
|
||||
queue = async.queue((task, cb)->
|
||||
console.log("running task")
|
||||
task(cb)
|
||||
, 1)
|
||||
|
||||
console.log("hi there queue")
|
||||
queue.drain = ()->
|
||||
console.log('HI all items have been processed')
|
||||
|
||||
module.exports = UrlCache =
|
||||
downloadUrlToFile: (project_id, url, destPath, lastModified, callback = (error) ->) ->
|
||||
UrlCache._ensureUrlIsInCache project_id, url, lastModified, (error, pathToCachedUrl) =>
|
||||
|
@ -108,7 +100,7 @@ module.exports = UrlCache =
|
|||
db.UrlCache.find(where: { url: url, project_id: project_id })
|
||||
.then((urlDetails) -> cb null, urlDetails)
|
||||
.error cb
|
||||
queue.push job, callback
|
||||
dbQueue.queue.push job, callback
|
||||
|
||||
_updateOrCreateUrlDetails: (project_id, url, lastModified, callback = (error) ->) ->
|
||||
job = (cb)->
|
||||
|
@ -121,7 +113,7 @@ module.exports = UrlCache =
|
|||
.error(cb)
|
||||
)
|
||||
.error cb
|
||||
queue.push(job, callback)
|
||||
dbQueue.queue.push(job, callback)
|
||||
|
||||
_clearUrlDetails: (project_id, url, callback = (error) ->) ->
|
||||
job = (cb)->
|
||||
|
@ -129,7 +121,7 @@ module.exports = UrlCache =
|
|||
db.UrlCache.destroy(where: {url: url, project_id: project_id})
|
||||
.then(() -> cb null)
|
||||
.error cb
|
||||
queue.push(job, callback)
|
||||
dbQueue.queue.push(job, callback)
|
||||
|
||||
|
||||
_findAllUrlsInProject: (project_id, callback = (error, urls) ->) ->
|
||||
|
@ -141,7 +133,7 @@ module.exports = UrlCache =
|
|||
cb null, urlEntries.map((entry) -> entry.url)
|
||||
)
|
||||
.error cb
|
||||
queue.push(job, callback)
|
||||
dbQueue.queue.push(job, callback)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue