somewhat excessive caching for index pages

This commit is contained in:
Shish 2012-06-24 02:07:59 +01:00
parent 8dfeb7cda3
commit 0bc4ebafa5

View File

@ -158,7 +158,16 @@ class Index extends Extension {
$page_size = $event->get_page_size(); $page_size = $event->get_page_size();
try { try {
$total_pages = Image::count_pages($search_terms); $total_pages = Image::count_pages($search_terms);
if(SPEED_HAX && count($search_terms) == 0 && ($page_number < 10)) { // extra caching for the first few post/list pages
$images = $database->cache->get("post-list-$page_number");
if(!$images) {
$images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms); $images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms);
$database->cache->set("post-list-$page_number", $images, 600);
}
}
else {
$images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms);
}
} }
catch(SearchTermParseException $stpe) { catch(SearchTermParseException $stpe) {
// FIXME: display the error somewhere // FIXME: display the error somewhere
@ -194,6 +203,24 @@ class Index extends Extension {
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
public function onImageAddition(ImageAdditionEvent $event) {
global $database;
if(SPEED_HAX) {
for($i=1; $i<10; $i++) {
$database->cache->delete("post-list-$i");
}
}
}
public function onImageDeletion(ImageDeletionEvent $event) {
global $database;
if(SPEED_HAX) {
for($i=1; $i<10; $i++) {
$database->cache->delete("post-list-$i");
}
}
}
public function onSearchTermParse(SearchTermParseEvent $event) { public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array(); $matches = array();
// check for tags first as tag based searches are more common. // check for tags first as tag based searches are more common.