|
|
@@ -77,57 +77,66 @@ const RedisManager = {
|
|
|
logger.error({ err: error, docId, projectId }, error.message)
|
|
|
return callback(error)
|
|
|
}
|
|
|
- // update docsInProject set before writing doc contents
|
|
|
- rclient.sadd(
|
|
|
- keys.docsInProject({ project_id: projectId }),
|
|
|
- docId,
|
|
|
- error => {
|
|
|
- if (error) return callback(error)
|
|
|
-
|
|
|
- if (!pathname) {
|
|
|
- metrics.inc('pathname', 1, {
|
|
|
- path: 'RedisManager.setDoc',
|
|
|
- status: pathname === '' ? 'zero-length' : 'undefined',
|
|
|
- })
|
|
|
- }
|
|
|
+ setHistoryRangesSupportFlag(docId, historyRangesSupport, err => {
|
|
|
+ if (err) {
|
|
|
+ return callback(err)
|
|
|
+ }
|
|
|
+ // update docsInProject set before writing doc contents
|
|
|
+ rclient.sadd(
|
|
|
+ keys.docsInProject({ project_id: projectId }),
|
|
|
+ docId,
|
|
|
+ error => {
|
|
|
+ if (error) return callback(error)
|
|
|
|
|
|
- const multi = rclient.multi()
|
|
|
- multi.mset({
|
|
|
- [keys.docLines({ doc_id: docId })]: docLines,
|
|
|
- [keys.projectKey({ doc_id: docId })]: projectId,
|
|
|
- [keys.docVersion({ doc_id: docId })]: version,
|
|
|
- [keys.docHash({ doc_id: docId })]: docHash,
|
|
|
- [keys.ranges({ doc_id: docId })]: ranges,
|
|
|
- [keys.pathname({ doc_id: docId })]: pathname,
|
|
|
- [keys.projectHistoryId({ doc_id: docId })]: projectHistoryId,
|
|
|
- })
|
|
|
- if (historyRangesSupport) {
|
|
|
- multi.sadd(keys.historyRangesSupport(), docId)
|
|
|
- multi.del(keys.resolvedCommentIds({ doc_id: docId }))
|
|
|
- if (resolvedCommentIds.length > 0) {
|
|
|
- multi.sadd(
|
|
|
- keys.resolvedCommentIds({ doc_id: docId }),
|
|
|
- ...resolvedCommentIds
|
|
|
- )
|
|
|
+ if (!pathname) {
|
|
|
+ metrics.inc('pathname', 1, {
|
|
|
+ path: 'RedisManager.setDoc',
|
|
|
+ status: pathname === '' ? 'zero-length' : 'undefined',
|
|
|
+ })
|
|
|
}
|
|
|
- }
|
|
|
- multi.exec(err => {
|
|
|
- if (err) {
|
|
|
- callback(
|
|
|
- OError.tag(err, 'failed to write doc to Redis in MULTI', {
|
|
|
- previousErrors: err.previousErrors.map(e => ({
|
|
|
- name: e.name,
|
|
|
- message: e.message,
|
|
|
- command: e.command,
|
|
|
- })),
|
|
|
- })
|
|
|
- )
|
|
|
- } else {
|
|
|
- callback()
|
|
|
+
|
|
|
+ // Make sure that this MULTI operation only operates on doc
|
|
|
+ // specific keys, i.e. keys that have the doc id in curly braces.
|
|
|
+ // The curly braces identify a hash key for Redis and ensures that
|
|
|
+ // the MULTI's operations are all done on the same node in a
|
|
|
+ // cluster environment.
|
|
|
+ const multi = rclient.multi()
|
|
|
+ multi.mset({
|
|
|
+ [keys.docLines({ doc_id: docId })]: docLines,
|
|
|
+ [keys.projectKey({ doc_id: docId })]: projectId,
|
|
|
+ [keys.docVersion({ doc_id: docId })]: version,
|
|
|
+ [keys.docHash({ doc_id: docId })]: docHash,
|
|
|
+ [keys.ranges({ doc_id: docId })]: ranges,
|
|
|
+ [keys.pathname({ doc_id: docId })]: pathname,
|
|
|
+ [keys.projectHistoryId({ doc_id: docId })]: projectHistoryId,
|
|
|
+ })
|
|
|
+ if (historyRangesSupport) {
|
|
|
+ multi.del(keys.resolvedCommentIds({ doc_id: docId }))
|
|
|
+ if (resolvedCommentIds.length > 0) {
|
|
|
+ multi.sadd(
|
|
|
+ keys.resolvedCommentIds({ doc_id: docId }),
|
|
|
+ ...resolvedCommentIds
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
- )
|
|
|
+ multi.exec(err => {
|
|
|
+ if (err) {
|
|
|
+ callback(
|
|
|
+ OError.tag(err, 'failed to write doc to Redis in MULTI', {
|
|
|
+ previousErrors: err.previousErrors.map(e => ({
|
|
|
+ name: e.name,
|
|
|
+ message: e.message,
|
|
|
+ command: e.command,
|
|
|
+ })),
|
|
|
+ })
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ callback()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
|
|
|
@@ -143,6 +152,11 @@ const RedisManager = {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Make sure that this MULTI operation only operates on doc
|
|
|
+ // specific keys, i.e. keys that have the doc id in curly braces.
|
|
|
+ // The curly braces identify a hash key for Redis and ensures that
|
|
|
+ // the MULTI's operations are all done on the same node in a
|
|
|
+ // cluster environment.
|
|
|
let multi = rclient.multi()
|
|
|
multi.strlen(keys.docLines({ doc_id: docId }))
|
|
|
multi.del(
|
|
|
@@ -167,6 +181,12 @@ const RedisManager = {
|
|
|
// record bytes freed in redis
|
|
|
metrics.summary('redis.docLines', length, { status: 'del' })
|
|
|
}
|
|
|
+
|
|
|
+ // Make sure that this MULTI operation only operates on project
|
|
|
+ // specific keys, i.e. keys that have the project id in curly braces.
|
|
|
+ // The curly braces identify a hash key for Redis and ensures that
|
|
|
+ // the MULTI's operations are all done on the same node in a
|
|
|
+ // cluster environment.
|
|
|
multi = rclient.multi()
|
|
|
multi.srem(keys.docsInProject({ project_id: projectId }), docId)
|
|
|
multi.del(keys.projectState({ project_id: projectId }))
|
|
|
@@ -180,6 +200,11 @@ const RedisManager = {
|
|
|
},
|
|
|
|
|
|
checkOrSetProjectState(projectId, newState, callback) {
|
|
|
+ // Make sure that this MULTI operation only operates on project
|
|
|
+ // specific keys, i.e. keys that have the project id in curly braces.
|
|
|
+ // The curly braces identify a hash key for Redis and ensures that
|
|
|
+ // the MULTI's operations are all done on the same node in a
|
|
|
+ // cluster environment.
|
|
|
const multi = rclient.multi()
|
|
|
multi.getset(keys.projectState({ project_id: projectId }), newState)
|
|
|
multi.expire(keys.projectState({ project_id: projectId }), 30 * minutes)
|
|
|
@@ -488,6 +513,12 @@ const RedisManager = {
|
|
|
logger.error({ err: error, docId, ranges }, error.message)
|
|
|
return callback(error)
|
|
|
}
|
|
|
+
|
|
|
+ // Make sure that this MULTI operation only operates on doc
|
|
|
+ // specific keys, i.e. keys that have the doc id in curly braces.
|
|
|
+ // The curly braces identify a hash key for Redis and ensures that
|
|
|
+ // the MULTI's operations are all done on the same node in a
|
|
|
+ // cluster environment.
|
|
|
const multi = rclient.multi()
|
|
|
multi.mset({
|
|
|
[keys.docLines({ doc_id: docId })]: newDocLines,
|
|
|
@@ -670,6 +701,14 @@ const RedisManager = {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
+function setHistoryRangesSupportFlag(docId, historyRangesSupport, callback) {
|
|
|
+ if (historyRangesSupport) {
|
|
|
+ rclient.sadd(keys.historyRangesSupport(), docId, callback)
|
|
|
+ } else {
|
|
|
+ rclient.srem(keys.historyRangesSupport(), docId, callback)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
module.exports = RedisManager
|
|
|
module.exports.promises = promisifyAll(RedisManager, {
|
|
|
without: ['_deserializeRanges', '_computeHash'],
|