X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=server%2Fserve-analysis.js;h=41610e1439d733d2f73c0389351f711454a5e9a0;hb=f71f5c94d093acda1b39d23cf7a71a21c6a3122b;hp=ce1f89d5ca5bf65ae4f2db26ca4a560822831293;hpb=bfb31cc6182daab7087e2922fde47c3441e3eb65;p=remoteglot diff --git a/server/serve-analysis.js b/server/serve-analysis.js index ce1f89d..41610e1 100644 --- a/server/serve-analysis.js +++ b/server/serve-analysis.js @@ -93,8 +93,19 @@ var replace_json = function(new_json_contents, mtime) { } } + var parsed = JSON.parse(new_json_contents); + + if (parsed['internal']) { + if (parsed['internal']['grpc_backends'] && + hash_lookup.need_reinit(parsed['internal']['grpc_backends'])) { + hash_lookup.init(parsed['internal']['grpc_backends']); + } + delete parsed['internal']; + new_json_contents = JSON.stringify(parsed); + } + var new_json = { - parsed: JSON.parse(new_json_contents), + parsed: parsed, plain: new_json_contents, last_modified: mtime }; @@ -123,6 +134,17 @@ var create_json_historic_diff = function(new_json, history_left, new_diff_json, var histobj = history_left.shift(); var diff = delta.JSON_delta.diff(histobj.parsed, new_json.parsed); var diff_text = JSON.stringify(diff); + + // Verify that the delta is correct + var base = JSON.parse(histobj.plain); + delta.JSON_delta.patch(base, diff); + var correct_pv = JSON.stringify(base['pv']); + var wrong_pv = JSON.stringify(new_json.parsed['pv']); + if (correct_pv !== wrong_pv) { + console.log("Patch went wrong:", histobj.plain, new_json.plain); + exit(); + } + zlib.gzip(diff_text, function(err, buffer) { if (err) throw err; new_diff_json[histobj.last_modified] = { @@ -145,7 +167,7 @@ var reread_file = function(event, filename) { if (json_lock == 1) { // Already processing; wait a bit. json_lock = 2; - setTimeout(function() { json_lock = 1; reread_file(event, filename); }, 100); + setTimeout(function() { if (json_lock == 2) json_lock = 1; reread_file(event, filename); }, 100); return; } json_lock = 1; @@ -172,7 +194,7 @@ var reread_file = function(event, filename) { touch_timer = setTimeout(function() { console.log("Touching analysis.json due to no other activity"); var now = Date.now() / 1000; - fs.utimes(json_filename, now, now); + fs.utimes(json_filename, now, now, function() {}); }, 30000); } var possibly_wakeup_clients = function() {