@@ -88,6 +88,36 @@ sub cache_row_key ($) {
return join $; , map { $jr->{$_} } @cache_row_key_cols;
}
+our $jqcachemisses = 0;
+our $jqtotal = 0;
+
+sub cacheable_fn ($$$) {
+ my ($jr, $cachekey, $fn) = @_;
+ $jqtotal++;
+ $cachekey = '%'.$cachekey;
+ my $cached = $jr->{$cachekey};
+ $q_count{$cachekey}++;
+ if (!$cached) {
+ $jqcachemisses++;
+ $q_misses{$cachekey}++;
+ $cached = $fn->();
+ $jr->{$cachekey} = $cached;
+ }
+ return $cached;
+}
+
+sub cacheable_query ($$$) {
+ my ($q, $jr, $cachekey) = @_;
+ cacheable_fn($jr, $cachekey, sub {
+ foreach my $k (keys %{ $q->{ParamTypes} }) {
+ $k =~ m/^:/ or die "$k ?";
+ $q->bind_param($k, $jr->{$'} // die "$k ?");
+ }
+ $q->execute();
+ return $q->fetchrow_hashref();
+ });
+}
+
sub cache_read_previous ($) {
my ($html_file) = @_;
if (!open H, $html_file) {
@@ -182,36 +212,6 @@ END
print DEBUG "MINFLIGHT $minflight\n";
}
-our $jqcachemisses = 0;
-our $jqtotal = 0;
-
-sub cacheable_fn ($$$) {
- my ($jr, $cachekey, $fn) = @_;
- $jqtotal++;
- $cachekey = '%'.$cachekey;
- my $cached = $jr->{$cachekey};
- $q_count{$cachekey}++;
- if (!$cached) {
- $jqcachemisses++;
- $q_misses{$cachekey}++;
- $cached = $fn->();
- $jr->{$cachekey} = $cached;
- }
- return $cached;
-}
-
-sub cacheable_query ($$$) {
- my ($q, $jr, $cachekey) = @_;
- cacheable_fn($jr, $cachekey, sub {
- foreach my $k (keys %{ $q->{ParamTypes} }) {
- $k =~ m/^:/ or die "$k ?";
- $q->bind_param($k, $jr->{$'} // die "$k ?");
- }
- $q->execute();
- return $q->fetchrow_hashref();
- });
-}
-
our %hosts;
sub mainquery ($) {
Pure code motion. Brings these together with the other work-cacheing code. Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com> --- sg-report-host-history | 60 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-)