Răsfoiți Sursa

Merge pull request #1853 from overleaf/bg-check-doc-hashes-staged-rollout

enable sharejs hash checking

GitOrigin-RevId: 2c71d239b2f5ee2bee6baf03dd54aaa8afc6fae7
Brian Gough 7 ani în urmă
părinte
comite
c242a8d4c1

+ 3 - 0
services/web/app/views/project/editor.pug

@@ -175,6 +175,9 @@ block requirejs
 		window.aceWorkerPath = "#{aceWorkerPath}";
 		window.pdfCMapsPath = "#{pdfCMapsPath}"
 		window.uiConfig = JSON.parse('!{JSON.stringify(uiConfig).replace(/\//g, "\\/")}');
+		//- enable doc hash checking for projects created after 2019-06-09
+		//- this is for a staged rollout, eventually we will turn this on for all projects
+		window.useShareJsHash = (window.project_id > "5cfd8f700000000000000000")
 
 	- if (settings.overleaf != null)
 		script(type='text/javascript').

+ 11 - 3
services/web/public/js/libs/sharejs.js

@@ -1303,9 +1303,17 @@ define(['ace/ace','libs/sha1'], function () {
 
         this.emit('flipped_pending_to_inflight');
 
-        if (window.sl_debugging) {
-          // send git hash of current snapshot when debugging
-          var sha1 = CryptoJS.SHA1("blob " + this.snapshot.length + "\x00" + this.snapshot).toString()
+        if (window.useShareJsHash || window.sl_debugging) {
+          var now = Date.now()
+          var age = this.__lastSubmitTimestamp && (now - this.__lastSubmitTimestamp)
+          var RECOMPUTE_HASH_INTERVAL = 5000
+          // check the document hash regularly (but not if we have checked in the last 5 seconds)
+          var needToRecomputeHash = !this.__lastSubmitTimestamp || (age > RECOMPUTE_HASH_INTERVAL) || (age < 0) 
+          if (needToRecomputeHash || window.sl_debugging) {
+            // send git hash of current snapshot
+            var sha1 = CryptoJS.SHA1("blob " + this.snapshot.length + "\x00" + this.snapshot).toString()
+            this.__lastSubmitTimestamp = now;
+          }
         }
 
         // console.log "SENDING OP TO SERVER", @inflightOp, @version