set limit on how large of a resultset Clark will build graphs for
authorGalen Charlton <gmc@esilibrary.com>
Fri, 20 Mar 2015 20:33:39 +0000 (20:33 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 20 Mar 2015 20:33:39 +0000 (20:33 +0000)
Attempting to draw a bar chart on a 50,000-row result set
can consuming system resources for no particular purpose, so
by default Clark Kent will now refuse to generate a bar, pie, or line
chart if the resultset has more than 1,000 rows.  That limit
can be adjusted using a new command-line paramter for clark-kent.pl,
--max-rows-for-charts.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/reporter/clark-kent.pl

index 2e9bbd9..f2e4056 100755 (executable)
@@ -31,10 +31,15 @@ use open ':utf8';
 
 my ($count, $config, $sleep_interval, $lockfile, $daemon) = (1, 'SYSCONFDIR/opensrf_core.xml', 10, '/tmp/reporter-LOCK');
 
+# set upper bound on number of rows in the resultset
+# before Clark refuses to try to draw a chart
+my $max_rows_for_charts = 1000;
+
 GetOptions(
        "daemon"        => \$daemon,
        "sleep=i"       => \$sleep_interval,
        "concurrency=i" => \$count,
+       "max-rows-for-charts=i" => \$max_rows_for_charts,
        "bootstrap|boostrap=s"  => \$config,
        "lockfile=s"    => \$lockfile,
 );
@@ -544,28 +549,40 @@ sub build_html {
 
        # Time for a pie chart
        if ($r->{chart_pie}) {
-               my $pics = draw_pie($r, $file);
-               for my $pic (@$pics) {
-                       print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
+               if (scalar(@{$r->{data}}) > $max_rows_for_charts) {
+                       print $index "<strong>Report output has too many rows to make a pie chart</strong>$br4";
+               } else {
+                       my $pics = draw_pie($r, $file);
+                       for my $pic (@$pics) {
+                               print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
+                       }
                }
        }
 
        print $index $br4;
        # Time for a bar chart
        if ($r->{chart_bar}) {
-               my $pics = draw_bars($r, $file);
-               for my $pic (@$pics) {
-                       print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
+               if (scalar(@{$r->{data}}) > $max_rows_for_charts) {
+                       print $index "<strong>Report output has too many rows to make a bar chart</strong>$br4";
+               } else {
+                       my $pics = draw_bars($r, $file);
+                       for my $pic (@$pics) {
+                               print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
+                       }
                }
        }
 
        print $index $br4;
        # Time for a bar chart
        if ($r->{chart_line}) {
-               my $pics = draw_lines($r, $file);
-               for my $pic (@$pics) {
-                       print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
-               }
+               if (scalar(@{$r->{data}}) > $max_rows_for_charts) {
+                       print $index "<strong>Report output has too many rows to make a line chart</strong>$br4";
+               } else {
+                       my $pics = draw_lines($r, $file);
+                       for my $pic (@$pics) {
+                               print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
+                       }
+           }
        }
 
        # and that's it!