git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit 3e817258 authored by Evan Prodromou's avatar Evan Prodromou

cache user data for user sitemap

parent 946cd15e
...@@ -43,7 +43,8 @@ if (!defined('STATUSNET')) { ...@@ -43,7 +43,8 @@ if (!defined('STATUSNET')) {
class UsersitemapAction extends SitemapAction class UsersitemapAction extends SitemapAction
{ {
var $user = null; var $users = null;
var $j = 0;
function prepare($args) function prepare($args)
{ {
...@@ -61,37 +62,67 @@ class UsersitemapAction extends SitemapAction ...@@ -61,37 +62,67 @@ class UsersitemapAction extends SitemapAction
$d += 0; $d += 0;
$i += 0; $i += 0;
$offset = ($i-1) * SitemapPlugin::USERS_PER_MAP; $this->users = $this->getUsers($y, $m, $d, $i);
$limit = SitemapPlugin::USERS_PER_MAP; $this->j = 0;
return true;
}
$this->user = new User(); function nextUrl()
{
if ($this->j < count($this->users)) {
$nickname = $this->users[$this->j];
$this->j++;
return array(common_profile_url($nickname), null, null, null);
} else {
return null;
}
}
$begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d); function getUsers($y, $m, $d, $i)
{
$u = User::cacheGet("sitemap:user:$y:$m:$d:$i");
// XXX: estimates 1d == 24h, which screws up days if ($u === false) {
// with leap seconds (1d == 24h + 1s). Thankfully they're
// few and far between.
$enddt = common_sql_date(strtotime($begindt) + (24 * 60 * 60)); $user = new User();
$this->user->whereAdd("created >= '$begindt'"); $begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
$this->user->whereAdd("created < '$enddt'");
$this->user->orderBy('created'); // XXX: estimates 1d == 24h, which screws up days
// with leap seconds (1d == 24h + 1s). Thankfully they're
// few and far between.
$this->user->limit($offset, $limit); $theend = strtotime($begindt) + (24 * 60 * 60);
$enddt = common_sql_date($theend);
$this->user->find(); $user->selectAdd();
$user->selectAdd('nickname');
$user->whereAdd("created >= '$begindt'");
$user->whereAdd("created < '$enddt'");
return true; $user->orderBy('created');
}
function nextUrl() $offset = ($i-1) * SitemapPlugin::USERS_PER_MAP;
{ $limit = SitemapPlugin::USERS_PER_MAP;
if ($this->user->fetch()) {
return array(common_profile_url($this->user->nickname), null, null, null); $user->limit($offset, $limit);
} else {
return null; $user->find();
while ($user->fetch()) {
$u[] = $user->nickname;
}
$c = Cache::instance();
if (!empty($c)) {
$c->set(Cache::key("sitemap:user:$y:$m:$d:$i"),
$u,
Cache::COMPRESSED,
((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60)));
}
} }
return $u;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment