Просмотр исходного кода

Merge pull request #11287 from overleaf/bg-clear-first-op-timestamp-2

clear the first op timestamp whenever the queue is processed (2nd attempt)

GitOrigin-RevId: 0764ca6360b2a9203e5d32499213b312563a2c47
Miguel Serrano 3 лет назад
Родитель
Сommit
98cf5765e9

+ 6 - 1
services/project-history/app/js/RedisManager.js

@@ -234,6 +234,7 @@ _mocks.deleteAppliedDocUpdates = (project_id, updates, callback) => {
       status: 'lrem',
       status: 'lrem',
     })
     })
     multi.lrem(Keys.projectHistoryOps({ project_id }), 1, update)
     multi.lrem(Keys.projectHistoryOps({ project_id }), 1, update)
+    multi.del(Keys.projectHistoryFirstOpTimestamp({ project_id }))
   }
   }
   multi.exec(callback)
   multi.exec(callback)
 }
 }
@@ -247,7 +248,11 @@ export function destroyDocUpdatesQueue(project_id, callback) {
   if (callback == null) {
   if (callback == null) {
     callback = function () {}
     callback = function () {}
   }
   }
-  return rclient.del(Keys.projectHistoryOps({ project_id }), callback)
+  return rclient.del(
+    Keys.projectHistoryOps({ project_id }),
+    Keys.projectHistoryFirstOpTimestamp({ project_id }),
+    callback
+  )
 }
 }
 
 
 // iterate over keys asynchronously using redis scan (non-blocking)
 // iterate over keys asynchronously using redis scan (non-blocking)

+ 10 - 0
services/project-history/test/unit/js/RedisManager/RedisManagerTests.js

@@ -27,6 +27,7 @@ describe('RedisManager', function () {
       lrange: sinon.stub(),
       lrange: sinon.stub(),
       lrem: sinon.stub(),
       lrem: sinon.stub(),
       srem: sinon.stub(),
       srem: sinon.stub(),
+      del: sinon.stub(),
     }
     }
     this.rclient.multi = sinon.stub().returns(this.rclient)
     this.rclient.multi = sinon.stub().returns(this.rclient)
     this.RedisWrapper = {
     this.RedisWrapper = {
@@ -39,6 +40,9 @@ describe('RedisManager', function () {
             projectHistoryOps({ project_id }) {
             projectHistoryOps({ project_id }) {
               return `Project:HistoryOps:${project_id}`
               return `Project:HistoryOps:${project_id}`
             },
             },
+            projectHistoryFirstOpTimestamp({ project_id }) {
+              return `ProjectHistory:FirstOpTimestamp:{${project_id}}`
+            },
           },
           },
         },
         },
       },
       },
@@ -132,6 +136,12 @@ describe('RedisManager', function () {
         .should.equal(true)
         .should.equal(true)
     })
     })
 
 
+    it('should clear the first op timestamp', function () {
+      return this.rclient.del
+        .calledWith(`ProjectHistory:FirstOpTimestamp:{${this.project_id}}`)
+        .should.equal(true)
+    })
+
     return it('should call the callback ', function () {
     return it('should call the callback ', function () {
       return this.callback.called.should.equal(true)
       return this.callback.called.should.equal(true)
     })
     })