mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
[misc] track delays of using sqlite for url caching details
This commit is contained in:
parent
d40065fd8e
commit
8f1ea7f0d1
1 changed files with 21 additions and 4 deletions
|
@ -21,6 +21,7 @@ const crypto = require('crypto')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const logger = require('logger-sharelatex')
|
const logger = require('logger-sharelatex')
|
||||||
const async = require('async')
|
const async = require('async')
|
||||||
|
const Metrics = require('./Metrics')
|
||||||
|
|
||||||
module.exports = UrlCache = {
|
module.exports = UrlCache = {
|
||||||
downloadUrlToFile(project_id, url, destPath, lastModified, callback) {
|
downloadUrlToFile(project_id, url, destPath, lastModified, callback) {
|
||||||
|
@ -206,17 +207,22 @@ module.exports = UrlCache = {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
callback = function (error, urlDetails) {}
|
callback = function (error, urlDetails) {}
|
||||||
}
|
}
|
||||||
|
const timer = new Metrics.Timer('db-find-url-details')
|
||||||
const job = (cb) =>
|
const job = (cb) =>
|
||||||
db.UrlCache.findOne({ where: { url, project_id } })
|
db.UrlCache.findOne({ where: { url, project_id } })
|
||||||
.then((urlDetails) => cb(null, urlDetails))
|
.then((urlDetails) => cb(null, urlDetails))
|
||||||
.error(cb)
|
.error(cb)
|
||||||
return dbQueue.queue.push(job, callback)
|
dbQueue.queue.push(job, (error, urlDetails) => {
|
||||||
|
timer.done()
|
||||||
|
callback(error, urlDetails)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateOrCreateUrlDetails(project_id, url, lastModified, callback) {
|
_updateOrCreateUrlDetails(project_id, url, lastModified, callback) {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
callback = function (error) {}
|
callback = function (error) {}
|
||||||
}
|
}
|
||||||
|
const timer = new Metrics.Timer('db-update-or-create-url-details')
|
||||||
const job = (cb) =>
|
const job = (cb) =>
|
||||||
db.UrlCache.findOrCreate({ where: { url, project_id } })
|
db.UrlCache.findOrCreate({ where: { url, project_id } })
|
||||||
.spread((urlDetails, created) =>
|
.spread((urlDetails, created) =>
|
||||||
|
@ -226,24 +232,32 @@ module.exports = UrlCache = {
|
||||||
.error(cb)
|
.error(cb)
|
||||||
)
|
)
|
||||||
.error(cb)
|
.error(cb)
|
||||||
return dbQueue.queue.push(job, callback)
|
dbQueue.queue.push(job, (error) => {
|
||||||
|
timer.done()
|
||||||
|
callback(error)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
_clearUrlDetails(project_id, url, callback) {
|
_clearUrlDetails(project_id, url, callback) {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
callback = function (error) {}
|
callback = function (error) {}
|
||||||
}
|
}
|
||||||
|
const timer = new Metrics.Timer('db-clear-url-details')
|
||||||
const job = (cb) =>
|
const job = (cb) =>
|
||||||
db.UrlCache.destroy({ where: { url, project_id } })
|
db.UrlCache.destroy({ where: { url, project_id } })
|
||||||
.then(() => cb(null))
|
.then(() => cb(null))
|
||||||
.error(cb)
|
.error(cb)
|
||||||
return dbQueue.queue.push(job, callback)
|
dbQueue.queue.push(job, (error) => {
|
||||||
|
timer.done()
|
||||||
|
callback(error)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
_findAllUrlsInProject(project_id, callback) {
|
_findAllUrlsInProject(project_id, callback) {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
callback = function (error, urls) {}
|
callback = function (error, urls) {}
|
||||||
}
|
}
|
||||||
|
const timer = new Metrics.Timer('db-find-urls-in-project')
|
||||||
const job = (cb) =>
|
const job = (cb) =>
|
||||||
db.UrlCache.findAll({ where: { project_id } })
|
db.UrlCache.findAll({ where: { project_id } })
|
||||||
.then((urlEntries) =>
|
.then((urlEntries) =>
|
||||||
|
@ -253,6 +267,9 @@ module.exports = UrlCache = {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.error(cb)
|
.error(cb)
|
||||||
return dbQueue.queue.push(job, callback)
|
dbQueue.queue.push(job, (err, urls) => {
|
||||||
|
timer.done()
|
||||||
|
callback(err, urls)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue