From 20a333cde8f035c3e76e08cfadef38f687846894 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 30 May 2009 18:01:59 +0000 Subject: [PATCH] Change caching on the SQLReport to be set by its cacheTimeout, even when viewed standalone, and not part of a page. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Wobject/SQLReport.pm | 14 ++++++ t/Asset/Wobject/SQLReport.t | 71 +++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 t/Asset/Wobject/SQLReport.t diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ee1082c5a..d8d35b573 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,7 @@ - fixed: Reverted bugfix for 10409 and changed the hover help to reflect the correct way to build list-type form controls in the MetaData. - fixed: Template parser cannot be set - fixed #10361: Shortcuts duplicate extra header tags + - fixed #10356: SQL report is cached too long 7.7.8 - fixed: Basic Auth doesn't work if password contains colon (Arjan Widlak, diff --git a/lib/WebGUI/Asset/Wobject/SQLReport.pm b/lib/WebGUI/Asset/Wobject/SQLReport.pm index 76b8bf3da..f6a0f6903 100644 --- a/lib/WebGUI/Asset/Wobject/SQLReport.pm +++ b/lib/WebGUI/Asset/Wobject/SQLReport.pm @@ -221,6 +221,20 @@ sub definition { #------------------------------------------------------------------- +=head2 getContentLastModified ( ) + +Override the base method, since SQL Report content can change without the asset being +touched. Default to using $self->get('cacheTimeout') seconds ago. + +=cut + +sub getContentLastModified { + my $self = shift; + return (time - $self->get("cacheTimeout")); +} + +#------------------------------------------------------------------- + =head2 getEditForm ( ) Manually make the edit form due to javascript for adding more queries. diff --git a/t/Asset/Wobject/SQLReport.t b/t/Asset/Wobject/SQLReport.t new file mode 100644 index 000000000..78f3c432c --- /dev/null +++ b/t/Asset/Wobject/SQLReport.t @@ -0,0 +1,71 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------ +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------ + +# Write a little about what this script tests. +# +# + +use FindBin; +use strict; +use lib "$FindBin::Bin/../../lib"; +use Test::More; +use Test::Deep; +use Data::Dumper; + +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; + +################################################################ +# +# setup session, users and groups for this test +# +################################################################ + +my $session = WebGUI::Test->session; + +my $tests = 4 + ; +plan tests => 1 + + $tests; + +#---------------------------------------------------------------------------- +# put your tests here + +my $class = 'WebGUI::Asset::Wobject::SQLReport'; +my $loaded = use_ok($class); + +SKIP: { + +skip "Unable to load module $class", $tests unless $loaded; + + +my $defaultNode = WebGUI::Asset->getDefault($session); + +my $report = $defaultNode->addChild({ + className => $class, + title => 'test report', + cacheTimeout => 50, + dqQuery1 => 'select * from users', +}); + +my $versionTag = WebGUI::VersionTag->getWorking($session); +WebGUI::Test->tagsToRollback($versionTag); +$versionTag->commit; + +isa_ok($report, 'WebGUI::Asset::Wobject::SQLReport'); + +is($report->get('cacheTimeout'), 50, 'cacheTimeout set correctly'); +ok(abs($report->getContentLastModified - (time - 50)) < 2, 'getContentLastModified overridden correctly'); + +$report->update({cacheTimeout => 250}); +ok(abs($report->getContentLastModified - (time - 250)) < 2, '... tracks cacheTimeout'); + +}