adding listings caching to Matrix
This commit is contained in:
parent
59c559354f
commit
c4cd3c0940
3 changed files with 57 additions and 8 deletions
|
|
@ -35,6 +35,7 @@ fixDefaultPostReceived($session);
|
||||||
addEuVatDbColumns( $session );
|
addEuVatDbColumns( $session );
|
||||||
addShippingDrivers( $session );
|
addShippingDrivers( $session );
|
||||||
addTransactionTaxColumns( $session );
|
addTransactionTaxColumns( $session );
|
||||||
|
addListingsCacheTimeoutToMatrix( $session );
|
||||||
|
|
||||||
finish($session);
|
finish($session);
|
||||||
|
|
||||||
|
|
@ -48,6 +49,16 @@ finish($session);
|
||||||
# print "DONE!\n" unless $quiet;
|
# 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 {
|
sub addTemplateAttachmentsTable {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my $create = q{
|
my $create = q{
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,14 @@ sub definition {
|
||||||
label => $i18n->get("statistics cache timeout label"),
|
label => $i18n->get("statistics cache timeout label"),
|
||||||
hoverHelp => $i18n->get("statistics cache timeout description")
|
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}, {
|
push(@{$definition}, {
|
||||||
assetName=>$i18n->get('assetName'),
|
assetName=>$i18n->get('assetName'),
|
||||||
|
|
@ -470,16 +478,30 @@ The criterium by which the listings should be sorted.
|
||||||
|
|
||||||
sub getListings {
|
sub getListings {
|
||||||
|
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
my $sort = shift || $session->scratch->get('matrixSort') || $self->get('defaultSort');
|
my $sort = shift || $session->scratch->get('matrixSort') || $self->get('defaultSort');
|
||||||
|
my $versionTag = WebGUI::VersionTag->getWorking($session, 1);
|
||||||
|
my ($listings, $listingsEncoded);
|
||||||
|
|
||||||
my $sortDirection = ' desc';
|
my $noCache =
|
||||||
if ($sort eq 'title'){
|
$session->var->isAdminOn
|
||||||
$sortDirection = ' asc';
|
|| $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
|
select
|
||||||
assetData.title,
|
assetData.title,
|
||||||
assetData.url,
|
assetData.url,
|
||||||
|
|
@ -500,8 +522,14 @@ assetData.revisionDate
|
||||||
and status='approved'
|
and status='approved'
|
||||||
order by ".$sort.$sortDirection;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -448,6 +448,16 @@ to increase performance. How long should we cache them?|,
|
||||||
lastUpdated => 0,
|
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' => {
|
'rating timeout description' => {
|
||||||
message => q|Set a timeout so that users are prevented from rating a given listing too often.|,
|
message => q|Set a timeout so that users are prevented from rating a given listing too often.|,
|
||||||
lastUpdated => 1135271460,
|
lastUpdated => 1135271460,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue