mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #52 from sharelatex/ja-expire-docops
Add script to expire existing DocOps lists
This commit is contained in:
commit
9f31402fb4
1 changed files with 44 additions and 0 deletions
44
services/document-updater/expire_docops.coffee
Normal file
44
services/document-updater/expire_docops.coffee
Normal file
|
@ -0,0 +1,44 @@
|
|||
Settings = require "settings-sharelatex"
|
||||
rclient = require("redis-sharelatex").createClient(Settings.redis.documentupdater)
|
||||
keys = Settings.redis.documentupdater.key_schema
|
||||
async = require "async"
|
||||
RedisManager = require "./app/js/RedisManager"
|
||||
|
||||
getKeysFromNode = (node, pattern, callback) ->
|
||||
cursor = 0 # redis iterator
|
||||
keySet = {} # use hash to avoid duplicate results
|
||||
# scan over all keys looking for pattern
|
||||
doIteration = (cb) ->
|
||||
node.scan cursor, "MATCH", pattern, "COUNT", 1000, (error, reply) ->
|
||||
return callback(error) if error?
|
||||
[cursor, keys] = reply
|
||||
console.log "SCAN", keys.length
|
||||
for key in keys
|
||||
keySet[key] = true
|
||||
if cursor == '0' # note redis returns string result not numeric
|
||||
return callback(null, Object.keys(keySet))
|
||||
else
|
||||
doIteration()
|
||||
doIteration()
|
||||
|
||||
getKeys = (pattern, callback) ->
|
||||
nodes = rclient.nodes?('master') || [ rclient ];
|
||||
console.log "GOT NODES", nodes.length
|
||||
doKeyLookupForNode = (node, cb) ->
|
||||
getKeysFromNode node, pattern, cb
|
||||
async.concatSeries nodes, doKeyLookupForNode, callback
|
||||
|
||||
TTL = 60 * 60 # 1 hour
|
||||
expireDocOps = (callback) ->
|
||||
getKeys keys.docOps(doc_id: "*"), (error, keys) ->
|
||||
async.mapSeries keys,
|
||||
(key, cb) ->
|
||||
console.log "EXPIRE #{key} #{RedisManager.DOC_OPS_TTL}"
|
||||
rclient.expire key, RedisManager.DOC_OPS_TTL, cb
|
||||
callback
|
||||
|
||||
setTimeout () -> # Give redis a chance to connect
|
||||
expireDocOps (error) ->
|
||||
throw error if error?
|
||||
process.exit()
|
||||
, 1000
|
Loading…
Reference in a new issue