Verify that JSON_delta does not have any strangeness. master
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 28 Jan 2020 16:32:54 +0000 (17:32 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 28 Jan 2020 16:32:54 +0000 (17:32 +0100)
server/serve-analysis.js

index 86f2d90..41610e1 100644 (file)
@@ -134,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] = {