From f951bbed37075d7b0b37273e0019ff2e86700816 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 6 Nov 2008 15:48:31 +0000 Subject: [PATCH] Added a better mechanism for calculating when content was last modified for cache headers. --- docs/changelog/7.x.x.txt | 2 + docs/gotcha.txt | 2 + docs/upgrades/upgrade_7.6.2-7.6.3.pl | 11 +++- lib/WebGUI/Asset.pm | 12 +++- lib/WebGUI/Asset/Post.pm | 6 -- lib/WebGUI/Asset/Wobject/Collaboration.pm | 6 -- lib/WebGUI/Asset/Wobject/SyndicatedContent.pm | 66 ++----------------- 7 files changed, 27 insertions(+), 78 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 586d52759..5315e458f 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,6 +1,8 @@ 7.6.3 - fixed #8989: Missing profile field "showOnline" for the UsersOnline macro. - Added DataTable to WebGUI.conf.original + - Added a better mechanism for calculating when content was last modified for + cache headers. - The Syndicated Content asset was rewritten, and now uses 35% less memory and is 400% faster. - fixed #9025: Testing function of UsersOnline macro fails. diff --git a/docs/gotcha.txt b/docs/gotcha.txt index df780f6ab..e7a61db9e 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -16,6 +16,8 @@ save you many hours of grief. there will be problems that the migration cannot handle. Check your Syndicated Content assets after upgrade to ensure they are still working as expected. + + * You must upgrade to 7.6.2 before you can upgrade to 7.6.3. 7.6.1 diff --git a/docs/upgrades/upgrade_7.6.2-7.6.3.pl b/docs/upgrades/upgrade_7.6.2-7.6.3.pl index 68d48cf7b..e0440748c 100644 --- a/docs/upgrades/upgrade_7.6.2-7.6.3.pl +++ b/docs/upgrades/upgrade_7.6.2-7.6.3.pl @@ -29,12 +29,21 @@ my $quiet; # this line required my $session = start(); # this line required # upgrade functions go here - +createLastUpdatedField($session); createFieldShowOnline($session); upgradeSyndicatedContentTemplates($session); finish($session); # this line required +#---------------------------------------------------------------------------- +sub createLastUpdatedField { + my $session = shift; + print "\tAdding last updated field to all assets... " unless $quiet; + my $db = $session->db; + $db->write("alter table assetData add column lastModified bigint"); + $db->write("update assetData set lastModified=revisionDate"); + print "DONE!\n" unless $quiet; +} #---------------------------------------------------------------------------- sub upgradeSyndicatedContentTemplates { diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index c1e318df0..719ee9494 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -475,6 +475,11 @@ sub definition { fieldType=>'hidden', defaultValue=>'pending' }, + lastModified=>{ + noFormPost=>1, + fieldType=>'hidden', + defaultValue=>time(), + }, assetSize=>{ noFormPost=>1, fieldType=>'hidden', @@ -1450,14 +1455,14 @@ sub getUrl { Returns the overall modification time of the object and its content in Unix epoch format, for the purpose of the Last-Modified HTTP header. Override this -for subclasses that contain content that is not solely dependent on the -revisionDate of the asset. +for subclasses that contain content that is not solely lastModified property, +which gets updated every time update() is called. =cut sub getContentLastModified { my $self = shift; - return $self->get("revisionDate"); + return $self->get("lastModified"); } @@ -2238,6 +2243,7 @@ to set the keywords for this asset. sub update { my $self = shift; my $properties = shift; + $properties->{lastModified} = time(); # if keywords were specified, then let's set them the right way if (exists $properties->{keywords}) { diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index ddb7d4531..3efa89461 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -324,12 +324,6 @@ sub formatContent { return $msg; } -#------------------------------------------------------------------- -# Too slow to try to find out children, just always assume new data -sub getContentLastModified { - return time(); -} - #------------------------------------------------------------------- sub getAutoCommitWorkflowId { my $self = shift; diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index c8fb0629b..f5608e40e 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -810,12 +810,6 @@ sub duplicate { return $newAsset; } -#------------------------------------------------------------------- -# Too slow to try to find out children, just always assume new data -sub getContentLastModified { - return time(); -} - #------------------------------------------------------------------- =head2 getEditTabs diff --git a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm index 68450700b..2b4b17132 100644 --- a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm +++ b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm @@ -200,6 +200,10 @@ sub generateFeed { # limit the feed to the maxium number of headlines $feed->limit_item($self->get('maxHeadlines')); + + # mark this asset as updated + $self->update({lastModified=>time}); + return $feed; } @@ -327,68 +331,6 @@ sub view { $cache->set($out,$self->get("cacheTimeout")); } return $out; - - - - my $rssFlavor = shift; - if ($rssFlavor eq "" && !$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) { - my $out = WebGUI::Cache->new($self->session,"view_".$self->getId)->get; - return $out if $out; - } - my $maxHeadlines = $self->_getMaxHeadlines; - my @validatedUrls = $self->_getValidatedUrls; - return $self->processTemplate({},$self->get('templateId')) unless (scalar(@validatedUrls)); - my $title=$self->get('title'); - - #We came into this subroutine as - my $rssObject=($rssFlavor) ? XML::RSS::Creator->new(version=>$rssFlavor) : undef; - - my %var; - - my($item_loop,$rss_feeds)=$self->_get_items(\@validatedUrls, $maxHeadlines); - - if (scalar(@$rss_feeds) < 1) { - return $self->processTemplate(\%var,undef,$self->{_viewTemplate}); - } - - if(@$rss_feeds == 1){ - if(@$rss_feeds == 1){ - #One feed. Put in the info from the feed. - # Make sure we have a channel to avoid runtime errors - my $channel = $rss_feeds->[0]->{channel}; - if ( $channel && ref $channel eq "HASH" ) { - $var{'channel.title'} = $channel->{title} || $title; - $var{'channel.link'} = $channel->{link}; - $var{'channel.description'} = $channel->{description}; - } - else { - $var{'channel.title'} = $title; - } - } - } - - $self->_createRSSURLs(\%var); - $var{item_loop} = $item_loop; - - if ($rssObject) { - $self->_constructRSS($rssObject,\%var); - my $rss=$rssObject->as_string; - $self->session->http->setMimeType('text/xml'); - - #Looks like a kludge, but what this does is put in the proper - #XSLT stylesheet so the RSS doesn't look like total ass. - my $siteURL=$self->session->url->getSiteURL().$self->session->url->gateway(); - $rss=~s|<\?xml version="1\.0" encoding="UTF\-8"\?>|<\?xml version="1\.0" encoding="UTF\-8"\?>\n\n|; - return $rss; - - } else { - my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate}); - if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) { - WebGUI::Cache->new($self->session,"view_".$self->getId)->set($out,$self->get("cacheTimeout")); - } - return $out; - } - } #-------------------------------------------------------------------