diff --git a/docs/upgrades/upgrade_7.7.5-7.7.6.pl b/docs/upgrades/upgrade_7.7.5-7.7.6.pl index 51f18d874..e2abc490a 100644 --- a/docs/upgrades/upgrade_7.7.5-7.7.6.pl +++ b/docs/upgrades/upgrade_7.7.5-7.7.6.pl @@ -35,6 +35,7 @@ fixDefaultPostReceived($session); addEuVatDbColumns( $session ); addShippingDrivers( $session ); addTransactionTaxColumns( $session ); +addListingsCacheTimeoutToMatrix( $session ); finish($session); @@ -48,6 +49,16 @@ finish($session); # print "DONE!\n" unless $quiet; #} +#---------------------------------------------------------------------------- +sub addListingsCacheTimeoutToMatrix{ + my $session = shift; + print "\tAdding listingsCacheTimeout setting to Matrix table... " unless $quiet; + $session->db->write("alter table Matrix add listingsCacheTimeout int(11) not null default 3600;"); + print "Done.\n" unless $quiet; +} + +#---------------------------------------------------------------------------- + sub addTemplateAttachmentsTable { my $session = shift; my $create = q{ diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index 129195f34..c8e0a1087 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -260,6 +260,14 @@ sub definition { label => $i18n->get("statistics cache timeout label"), hoverHelp => $i18n->get("statistics cache timeout description") }, + listingsCacheTimeout => { + tab => "display", + fieldType => "interval", + defaultValue => 3600, + uiLevel => 8, + label => $i18n->get("listings cache timeout label"), + hoverHelp => $i18n->get("listings cache timeout description") + }, ); push(@{$definition}, { assetName=>$i18n->get('assetName'), @@ -470,16 +478,30 @@ The criterium by which the listings should be sorted. sub getListings { - my $self = shift; - my $session = $self->session; - my $sort = shift || $session->scratch->get('matrixSort') || $self->get('defaultSort'); + my $self = shift; + my $session = $self->session; + my $sort = shift || $session->scratch->get('matrixSort') || $self->get('defaultSort'); + my $versionTag = WebGUI::VersionTag->getWorking($session, 1); + my ($listings, $listingsEncoded); - my $sortDirection = ' desc'; - if ($sort eq 'title'){ - $sortDirection = ' asc'; + my $noCache = + $session->var->isAdminOn + || $self->get("listingsCacheTimeout") <= 10 + || ($versionTag && $versionTag->getId eq $self->get("tagId")); + unless ($noCache) { + $listingsEncoded = WebGUI::Cache->new($session,"matrixListings_".$self->getId)->get; } - my $sql = " + if ($listingsEncoded){ + $listings = JSON->new->decode($listingsEncoded); + } + else{ + my $sortDirection = ' desc'; + if ($sort eq 'title'){ + $sortDirection = ' asc'; + } + + my $sql = " select assetData.title, assetData.url, @@ -500,8 +522,14 @@ assetData.revisionDate and status='approved' order by ".$sort.$sortDirection; - return $session->db->buildArrayRefOfHashRefs($sql,[$self->getId]); + $listings = $session->db->buildArrayRefOfHashRefs($sql,[$self->getId]); + $listingsEncoded = JSON->new->encode($listings); + WebGUI::Cache->new($session,"matrixListings_".$self->getId)->set( + $listingsEncoded,$self->get("listingsCacheTimeout") + ); + } + return $listings; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/i18n/English/Asset_Matrix.pm b/lib/WebGUI/i18n/English/Asset_Matrix.pm index 3746c3cf1..38d8422e1 100644 --- a/lib/WebGUI/i18n/English/Asset_Matrix.pm +++ b/lib/WebGUI/i18n/English/Asset_Matrix.pm @@ -448,6 +448,16 @@ to increase performance. How long should we cache them?|, lastUpdated => 0, }, + 'listings cache timeout label' => { + message => q|Listings Cache Timeout|, + lastUpdated => 0, + }, + + 'listings cache timeout description' => { + message => q|The complete list of Matrix listings can be cached for some time to increase performance. How long should we cache it?|, + lastUpdated => 0, + }, + 'rating timeout description' => { message => q|Set a timeout so that users are prevented from rating a given listing too often.|, lastUpdated => 1135271460,