LP#1516867: set limit on when HTML report output sorting collab/gmcharlt/lp1516867_sortable_report_output
authorGalen Charlton <gmc@esilibrary.com>
Fri, 20 Nov 2015 21:26:05 +0000 (21:26 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 20 Nov 2015 21:29:43 +0000 (21:29 +0000)
To avoid taking an excessive amount of time to render an
HTML report or sort its values, dynamic sorting is enabled
only when there are at most 10,000 rows of output.

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

index 758cb2c..fabd2db 100755 (executable)
@@ -113,6 +113,12 @@ my $resultset_limit     = $opt_resultset_limit //
                           0;
 $resultset_limit = 0 unless $resultset_limit =~ /^\d+$/; # 0 means no limit
 
+# What follows is an emperically-derived magic number; if
+# the row count is larger than this, the table-sorting JavaScript
+# won't be loaded to excessive churn when viewing HTML reports
+# in the staff client or web browser.
+my $sortable_limit = 10000;
+
 my ($dbh,$running,$sth,@reports,$run, $current_time);
 
 if ($daemon) {
@@ -555,7 +561,6 @@ sub build_html {
                                td,th { border: solid black 1px; }
                                * { font-family: sans-serif; }
                        </style>
-                       <script src="/js/sortable/sortable.min.js"></script>
                        <link rel="stylesheet" href="/js/sortable/sortable-theme-minimal.css" />
                CSS
 
@@ -566,7 +571,11 @@ sub build_html {
                        print $raw "<tr><td>".join('</td><td>', @$_)."</td></tr>\n" for (@{$r->{data}});
                }
 
-               print $raw '</tbody></table></body></html>';
+               print $raw '</tbody></table>';
+               if (@{ $r->{data} } <= $sortable_limit) {
+                       print $raw '<script src="/js/sortable/sortable.min.js"></script>';
+               }
+               print $raw '</body></html>';
        
                $raw->close;
        }
index 373418e..539a576 100644 (file)
@@ -2,4 +2,5 @@ Sortable HTML reports
 ^^^^^^^^^^^^^^^^^^^^^
 HTML reports can now be sorted by clicking on the header for a given column.
 Clicking on the header toggles between sorting the column in ascending and
-descending order.
+descending order. Note that sorting is available only when there are
+at most 10,000 rows of output.