summaryrefslogtreecommitdiff
path: root/plugins/Sitemap
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-04-12 11:52:19 -0400
committerEvan Prodromou <evan@status.net>2010-06-01 13:52:27 -0700
commit946cd15e8bc12bece4a14a07c6e109c3d8904a66 (patch)
tree52e6cd7674f9aaf9c7f91fe814e595c5e01a1c9f /plugins/Sitemap
parent610d8021d8653822dbc52f0790eee41e4db38c17 (diff)
cache results of notice sitemap query
Diffstat (limited to 'plugins/Sitemap')
-rw-r--r--plugins/Sitemap/noticesitemap.php53
1 files changed, 34 insertions, 19 deletions
diff --git a/plugins/Sitemap/noticesitemap.php b/plugins/Sitemap/noticesitemap.php
index 6cf2b3d01..bc8a7bfd6 100644
--- a/plugins/Sitemap/noticesitemap.php
+++ b/plugins/Sitemap/noticesitemap.php
@@ -84,37 +84,52 @@ class NoticesitemapAction extends SitemapAction
function getNotices($y, $m, $d, $i)
{
- $offset = ($i-1) * SitemapPlugin::NOTICES_PER_MAP;
- $limit = SitemapPlugin::NOTICES_PER_MAP;
+ $n = Notice::cacheGet("sitemap:notice:$y:$m:$d:$i");
- $notice = new Notice();
+ if ($n === false) {
- $begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
+ $notice = new Notice();
- // XXX: estimates 1d == 24h, which screws up days
- // with leap seconds (1d == 24h + 1s). Thankfully they're
- // few and far between.
+ $begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
- $enddt = common_sql_date(strtotime($begindt) + (24 * 60 * 60));
+ // XXX: estimates 1d == 24h, which screws up days
+ // with leap seconds (1d == 24h + 1s). Thankfully they're
+ // few and far between.
- $notice->selectAdd();
- $notice->selectAdd('id, created');
+ $theend = strtotime($begindt) + (24 * 60 * 60);
+ $enddt = common_sql_date($theend);
- $notice->whereAdd("created >= '$begindt'");
- $notice->whereAdd("created < '$enddt'");
+ $notice->selectAdd();
+ $notice->selectAdd('id, created');
- $notice->whereAdd('is_local != 0');
+ $notice->whereAdd("created >= '$begindt'");
+ $notice->whereAdd("created < '$enddt'");
- $notice->orderBy('created');
+ $notice->whereAdd('is_local != 0');
- $notice->limit($offset, $limit);
+ $notice->orderBy('created');
- $notice->find();
+ $offset = ($i-1) * SitemapPlugin::NOTICES_PER_MAP;
+ $limit = SitemapPlugin::NOTICES_PER_MAP;
- $n = array();
+ $notice->limit($offset, $limit);
- while ($notice->fetch()) {
- $n[] = array($notice->id, $notice->created);
+ $notice->find();
+
+ $n = array();
+
+ while ($notice->fetch()) {
+ $n[] = array($notice->id, $notice->created);
+ }
+
+ $c = Cache::instance();
+
+ if (!empty($c)) {
+ $c->set(Cache::key("sitemap:notice:$y:$m:$d:$i"),
+ $n,
+ Cache::COMPRESSED,
+ ((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60)));
+ }
}
return $n;