From 39e7820520d08a35817ced858ae290a39e027bce Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 27 Feb 2019 09:03:28 -0700 Subject: [PATCH] Just send unified diff to client, not full old & new value --- api/src/Storage/History.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/api/src/Storage/History.php b/api/src/Storage/History.php index f3be3807d1..f21393506c 100644 --- a/api/src/Storage/History.php +++ b/api/src/Storage/History.php @@ -260,6 +260,17 @@ class History $row[$field] = explode(Tracking::ONE2N_SEPERATOR,$row[$field]); } } + if ($row['history_old_value'] !== Tracking::DIFF_MARKER && ( + $this->needs_diff($row['history_status'], $row['history_old_value']) || + $this->needs_diff($row['history_status'], $row['history_old_value']) + )) + { + // Larger text stored with full old / new value - calculate diff and just send that + $diff = new \Text_Diff('auto', array(explode("\n",$row['history_new_value']), explode("\n",$row['history_old_value']))); + $renderer = new \Text_Diff_Renderer_unified(); + $row['history_new_value'] = $renderer->render($diff); + $row['history_old_value'] = Tracking::DIFF_MARKER; + } // Get information needed for proper display if($row['history_appname'] == 'filemanager') { @@ -297,4 +308,10 @@ class History return $total; } + + protected function needs_diff($name, $value) + { + return $name == 'note' || $name == 'description' || + ($value && (strlen($value) > 50 || strstr($value, "\n") !== FALSE)); + } }