Browse files

Adding caching to a bunch of Smarty templates to ease the CPU we cons…

…ume on the server, mostly caused by Google's crawler
  • Loading branch information...
1 parent b69be42 commit d95e3c61e9e57dd7e4faaca2d0670765786adec0 @okvivi okvivi committed Jan 14, 2013
View
3 .gitignore
@@ -20,6 +20,9 @@ secret
tmp
*.sw?
+# Ignore smarty cache files
+www/cache/*
+
# Ignore vagrant status file
.vagrant
View
1 tools/push_to_web.sh
@@ -17,6 +17,7 @@ mirror -v -R --ignore-time \
-X '.git/*' \
-X '*.DS_Store' \
-X 'secret/db_user.php' \
+ -X 'cache/*' \
./ /www/www
quit 0
EOF
View
14 www/mods/cdep_2008_compact.php
@@ -7,12 +7,16 @@
mod_cdep_2008_summary();
$t = new Smarty();
-$t->assign('cid', $cid);
-$t->assign('idperson', $person->id);
-$t->assign('name', $person->getUrlName());
-$t->assign('votes', mod_cdep_2008_get_votes($person, 5));
-$t->display('mod_cdep_2008_most_recent_votes.tpl');
+$t->caching = 1;
+
+if (!$t->is_cached('mod_cdep_2008_most_recent_votes.tpl', $person->id)) {
+ $t->assign('cid', $cid);
+ $t->assign('idperson', $person->id);
+ $t->assign('name', $person->getUrlName());
+ $t->assign('votes', mod_cdep_2008_get_votes($person, 5));
+}
+$t->display('mod_cdep_2008_most_recent_votes.tpl', $person->id);
showBeliefs('cdep', '2008', $uid, $person->id);
View
14 www/mods/news_compact.php
@@ -2,11 +2,13 @@
$t = new Smarty();
-$t->assign('id', $person->id);
-$t->assign('title', $title);
-$t->assign('name', str_replace(' ', '+', $person->name));
-$t->assign('news', $person->getMostRecentNewsItems(7));
-
-$t->display('person_most_recent_news.tpl');
+$t->caching = 1;
+if (!$t->is_cached('person_most_recent_news.tpl', $person->id)) {
+ $t->assign('id', $person->id);
+ $t->assign('title', $title);
+ $t->assign('name', str_replace(' ', '+', $person->name));
+ $t->assign('news', $person->getMostRecentNewsItems(7));
+}
+$t->display('person_most_recent_news.tpl', $person->id);
?>
View
14 www/mods/person_declarations_compact.php
@@ -4,12 +4,14 @@
if (sizeof($declarations) > 0) {
$t = new Smarty();
+ $t->caching = 1;
- $t->assign('id', $person->id);
- $t->assign('name', $person->getNameForUrl());
- $t->assign('person', $person);
- $t->assign('declarations', $declarations);
-
- $t->display('mod_person_declarations_compact.tpl');
+ if (!$t->is_cached('mod_person_declarations_compact.tpl', $person->id)) {
+ $t->assign('id', $person->id);
+ $t->assign('name', $person->getNameForUrl());
+ $t->assign('person', $person);
+ $t->assign('declarations', $declarations);
+ }
+ $t->display('mod_person_declarations_compact.tpl', $person->id);
}
?>
View
11 www/mods/results_2012_compact.php
@@ -4,12 +4,15 @@
$t = new Smarty();
-$t->assign("college_name", $college);
+$t->caching = 1;
-$t->assign("compact", true);
-$t->assign("candidates", getCollegeCandidates($college, "2012"));
+if (!$t->is_cached("mod_results_2012.tpl", $college)) {
+ $t->assign("college_name", $college);
-$t->display("mod_results_2012.tpl");
+ $t->assign("compact", true);
+ $t->assign("candidates", getCollegeCandidates($college, "2012"));
+}
+$t->display("mod_results_2012.tpl", $college);
?>
View
77 www/pages/home_page/home_summary.php
@@ -10,44 +10,51 @@
$t = new Smarty();
-// Show the guys that show up most in the news.
-$list = getMostPresentInNews(10, NULL, NULL, NULL, NULL, NULL);
-$list = newsAddPreviousWeekToList($list, NULL, '%');
-$t->assign('topPeople', $list);
+// Enable custom caching times.
+$t->caching = 2;
-if ($uid > 0) {
+// Cache this for 20 minutes.
+$t->cache_lifetime = 1200;
+
+if (!$t->is_cached('home_page_summary.tpl')) {
// Show the guys that show up most in the news.
- $followList = getMostPresentInNews(10, NULL, NULL, NULL,
- followedPeopleIdsAsArray(), NULL);
- $followList = newsAddPreviousWeekToList($followList, NULL, '%');
-} else {
- $followList = array();
+ $list = getMostPresentInNews(10, NULL, NULL, NULL, NULL, NULL);
+ $list = newsAddPreviousWeekToList($list, NULL, '%');
+ $t->assign('topPeople', $list);
+
+ if ($uid > 0) {
+ // Show the guys that show up most in the news.
+ $followList = getMostPresentInNews(10, NULL, NULL, NULL,
+ followedPeopleIdsAsArray(), NULL);
+ $followList = newsAddPreviousWeekToList($followList, NULL, '%');
+ } else {
+ $followList = array();
+ }
+ $t->assign('followedPeople', $followList);
+
+ $t->assign('news', getMostRecentNewsArticles(NULL, NULL, 7, '%'));
+ $t->assign('blogposts', getMostRecentBlogPosts(7));
+
+ $t->assign("links", getMostRecentUgcLinks(3, NULL, 0, time() - 3 * 86400));
+
+ // Get the top three senators.
+ $t->assign('top_senators', getSenatSorted(3, 'DESC', 3));
+ $t->assign('bottom_senators',array_reverse(getSenatSorted(3, 'ASC', 3)));
+
+ // Get the top three senators.
+ $t->assign('top_cdep', getCdepSorted(3, 'DESC', 3));
+ $t->assign('bottom_cdep', array_reverse(getCdepSorted(3, 'ASC', 3)));
+
+ $parties = array(
+ array("id" => "1", "logo" => "images/parties/1.gif"),
+ array("id" => "2", "logo" => "images/parties/2.png"),
+ array("id" => "7", "logo" => "images/parties/7.jpg"),
+ array("id" => "14", "logo" => "images/parties/14.jpg"),
+ );
+ $t->assign('parties', $parties);
+
+ $t->assign('declarations', getMostRecentDeclarations());
}
-$t->assign('followedPeople', $followList);
-
-$t->assign('news', getMostRecentNewsArticles(NULL, NULL, 7, '%'));
-$t->assign('blogposts', getMostRecentBlogPosts(7));
-
-$t->assign("links", getMostRecentUgcLinks(3, NULL, 0, time() - 3 * 86400));
-
-// Get the top three senators.
-$t->assign('top_senators', getSenatSorted(3, 'DESC', 3));
-$t->assign('bottom_senators',array_reverse(getSenatSorted(3, 'ASC', 3)));
-
-// Get the top three senators.
-$t->assign('top_cdep', getCdepSorted(3, 'DESC', 3));
-$t->assign('bottom_cdep', array_reverse(getCdepSorted(3, 'ASC', 3)));
-
-$parties = array(
- array("id" => "1", "logo" => "images/parties/1.gif"),
- array("id" => "2", "logo" => "images/parties/2.png"),
- array("id" => "7", "logo" => "images/parties/7.jpg"),
- array("id" => "14", "logo" => "images/parties/14.jpg"),
-);
-$t->assign('parties', $parties);
-
-$t->assign('declarations', getMostRecentDeclarations());
-
$t->display('home_page_summary.tpl');
?>
View
7 www/person.php
@@ -134,8 +134,11 @@ function isExpandedModule($str) {
$t->display("person_sidebar_follow_button.tpl");
$t = new Smarty();
-$t->assign('qualifiers', $person->getNewsQualifiers(10));
-$t->display('person_qualifiers.tpl');
+$t->caching = 1;
+if (!$t->is_cached('person_qualifiers.tpl', $person->id)) {
+ $t->assign('qualifiers', $person->getNewsQualifiers(10));
+}
+$t->display('person_qualifiers.tpl', $person->id);
$college_name = $person->getActiveParliamentElectoralCollege();
if ($college_name) {

0 comments on commit d95e3c6

Please sign in to comment.