From 9a19cfb9de5d2b1aea150a38faeb7d0e11a9bd01 Mon Sep 17 00:00:00 2001 From: vrana Date: Wed, 1 Aug 2012 23:15:42 -0700 Subject: [PATCH] Limit amount of chart data passed to browser Summary: Firefox has a limit of ~500,000 elements which can be passed in literal array. This amount of data is meaningless anyway because even Retina displays don't have such resolution. Limit the amount of data to mitigate browser limitations and also reduce the page size. Ensure that first and last element is passed. I considered also reducing the granularity to days but I want new repositories to have nice precise graph. Test Plan: Displayed the chart in Firefox. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3134 --- .../controller/PhabricatorFactChartController.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/applications/fact/controller/PhabricatorFactChartController.php b/src/applications/fact/controller/PhabricatorFactChartController.php index 1872e065b3..302ab6afda 100644 --- a/src/applications/fact/controller/PhabricatorFactChartController.php +++ b/src/applications/fact/controller/PhabricatorFactChartController.php @@ -51,6 +51,20 @@ final class PhabricatorFactChartController extends PhabricatorFactController { throw new Exception("No data to show!"); } + // Limit amount of data passed to browser. + $count = count($points); + $limit = 2000; + if ($count > $limit) { + $i = 0; + $every = ceil($count / $limit); + foreach ($points as $epoch => $sum) { + $i++; + if ($i % $every && $i != $count) { + unset($points[$epoch]); + } + } + } + $x = array_keys($points); $y = array_values($points);