Skip to content

Commit

Permalink
Add memcache to MP recent appearances.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Apr 8, 2010
1 parent f7082ec commit 5a39916
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 41 deletions.
8 changes: 5 additions & 3 deletions www/includes/easyparliament/member.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,11 @@ function set_users_mp () {
// Grabs extra information (e.g. external links) from the database
# DISPLAY is whether it's to be displayed on MP page.
function load_extra_info($display = false) {

$memcache = new Memcache;
$memcache->connect('localhost', 11211);
global $memcache;
if (!$memcache) {
$memcache = new Memcache;
$memcache->connect('localhost', 11211);
}
$this->extra_info = $memcache->get(OPTION_TWFY_DB_NAME . ':extra_info:' . $this->person_id);
if ($this->extra_info) {
return;
Expand Down
88 changes: 50 additions & 38 deletions www/includes/easyparliament/templates/html/person.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,51 +568,63 @@ function person_committees_and_topics($member, $extra_info) {
}

function person_recent_appearances($member) {
global $DATA, $SEARCHENGINE, $this_page;
global $DATA, $SEARCHENGINE, $this_page;

echo '<a name="hansard"></a>';
$title = 'Most recent appearances';
if ($rssurl = $DATA->page_metadata($this_page, 'rss')) {
$title = '<a href="' . WEBPATH . $rssurl . '"><img src="' . WEBPATH . 'images/rss.gif" alt="RSS feed" border="0" align="right"></a> ' . $title;
}
echo '<a name="hansard"></a>';
$title = 'Most recent appearances';
if ($rssurl = $DATA->page_metadata($this_page, 'rss')) {
$title = '<a href="' . WEBPATH . $rssurl . '"><img src="' . WEBPATH . 'images/rss.gif" alt="RSS feed" border="0" align="right"></a> ' . $title;
}

print "<h4>$title</h4>";

//$this->block_start(array('id'=>'hansard', 'title'=>$title));
// This is really far from ideal - I don't really want $PAGE to know
// anything about HANSARDLIST / DEBATELIST / WRANSLIST.
// But doing this any other way is going to be a lot more work for little
// benefit unfortunately.
twfy_debug_timestamp();
$HANSARDLIST = new HANSARDLIST();

$searchstring = "speaker:$member[person_id]";
$SEARCHENGINE = new SEARCHENGINE($searchstring);
$args = array (
's' => $searchstring,
'p' => 1,
'num' => 3,
'pop' => 1,
'o' => 'd',
);
$HANSARDLIST->display('search_min', $args);
twfy_debug_timestamp();
print "<h4>$title</h4>";

//$this->block_start(array('id'=>'hansard', 'title'=>$title));
// This is really far from ideal - I don't really want $PAGE to know
// anything about HANSARDLIST / DEBATELIST / WRANSLIST.
// But doing this any other way is going to be a lot more work for little
// benefit unfortunately.
twfy_debug_timestamp();

global $memcache;
if (!$memcache) {
$memcache = new Memcache;
$memcache->connect('localhost', 11211);
}
$recent = $memcache->get(OPTION_TWFY_DB_NAME . ':recent_appear:' . $member['person_id']);
if (!$recent) {
$HANSARDLIST = new HANSARDLIST();
$searchstring = "speaker:$member[person_id]";
$SEARCHENGINE = new SEARCHENGINE($searchstring);
$args = array (
's' => $searchstring,
'p' => 1,
'num' => 3,
'pop' => 1,
'o' => 'd',
);
ob_start();
$HANSARDLIST->display('search_min', $args);
$recent = ob_get_clean();
$memcache->set(OPTION_TWFY_DB_NAME . ':recent_appear:' . $member['person_id'], $recent, 0, 3600);
}
print $recent;
twfy_debug_timestamp();

$MOREURL = new URL('search');
$MOREURL->insert( array('pid'=>$member['person_id'], 'pop'=>1) );
?>
$MOREURL = new URL('search');
$MOREURL->insert( array('pid'=>$member['person_id'], 'pop'=>1) );
?>
<p id="moreappear"><a href="<?php echo $MOREURL->generate(); ?>#n4">More of <?php echo ucfirst($member['full_name']); ?>'s recent appearances</a></p>

<?php
if ($rssurl = $DATA->page_metadata($this_page, 'rss')) {
// If we set an RSS feed for this page.
$HELPURL = new URL('help');
?>
<p class="unneededprintlinks"><a href="<?php echo WEBPATH . $rssurl; ?>" title="XML version of this person's recent appearances">RSS feed</a> (<a href="<?php echo $HELPURL->generate(); ?>#rss" title="An explanation of what RSS feeds are for">?</a>)</p>
if ($rssurl = $DATA->page_metadata($this_page, 'rss')) {
// If we set an RSS feed for this page.
$HELPURL = new URL('help');
?>
<p class="unneededprintlinks"><a href="<?php echo WEBPATH . $rssurl; ?>" title="XML version of this person's recent appearances">RSS feed</a> (<a href="<?php echo $HELPURL->generate(); ?>#rss" title="An explanation of what RSS feeds are for">?</a>)</p>
<?php
}
// $this->block_end();
}

// $this->block_end();

}

Expand Down

0 comments on commit 5a39916

Please sign in to comment.