make navigation use cache
This commit is contained in:
parent
b3192c3bbb
commit
f35adb3f51
@ -11,32 +11,50 @@ class ComicPressNavigation {
|
|||||||
|
|
||||||
function get_post_nav($post) {
|
function get_post_nav($post) {
|
||||||
$nav = array();
|
$nav = array();
|
||||||
|
if (is_object($post)) {
|
||||||
// global previous/next
|
if (isset($post->ID)) {
|
||||||
foreach (array('previous', 'next') as $field) {
|
$cache_key = 'navigation-' . $post->ID;
|
||||||
$nav[$field] = $this->_dbi->{"get_${field}_comic"}(null, $post);
|
|
||||||
}
|
if (($result = wp_cache_get($cache_key, 'comicpress')) !== false) {
|
||||||
|
foreach ($result as $key => $post_id) {
|
||||||
// global first/last
|
$nev[$key] = get_post($post_id);
|
||||||
foreach (array('first', 'last') as $field) {
|
}
|
||||||
$nav[$field] = $this->_dbi->{"get_${field}_comic"}(null);
|
}
|
||||||
}
|
|
||||||
|
// global previous/next
|
||||||
if ($category = $this->_storyline->get_valid_post_category($post->ID)) {
|
foreach (array('previous', 'next') as $field) {
|
||||||
// storyline previous/next
|
$nav[$field] = $this->_dbi->{"get_${field}_comic"}(null, $post);
|
||||||
foreach (array('previous', 'next') as $field) {
|
}
|
||||||
$nav["storyline-${field}"] = $this->_dbi->{"get_${field}_comic"}($category, $post);
|
|
||||||
}
|
// global first/last
|
||||||
|
foreach (array('first', 'last') as $field) {
|
||||||
// adjacent storyline nodes
|
$nav[$field] = $this->_dbi->{"get_${field}_comic"}(null);
|
||||||
if (is_array($valid = $this->_storyline->valid($category))) {
|
}
|
||||||
foreach ($valid as $field) {
|
|
||||||
$nav["storyline-chapter-${field}"] = $this->_dbi->get_first_comic($this->_storyline->{$field}($category));
|
if ($category = $this->_storyline->get_valid_post_category($post->ID)) {
|
||||||
}
|
// storyline previous/next
|
||||||
}
|
foreach (array('previous', 'next') as $field) {
|
||||||
}
|
$nav["storyline-${field}"] = $this->_dbi->{"get_${field}_comic"}($category, $post);
|
||||||
|
}
|
||||||
return $nav;
|
|
||||||
|
// adjacent storyline nodes
|
||||||
|
if (is_array($valid = $this->_storyline->valid($category))) {
|
||||||
|
foreach ($valid as $field) {
|
||||||
|
$nav["storyline-chapter-${field}"] = $this->_dbi->get_first_comic($this->_storyline->{$field}($category));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache_data = array();
|
||||||
|
foreach ($nav as $key => $output_post) {
|
||||||
|
if (!empty($output_post)) { $cache_data[$key] = $output_post->ID; }
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_cache_set($cache_key, $cache_data, 'comicpress');
|
||||||
|
|
||||||
|
return $nav;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,11 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->nav->_dbi = $dbi;
|
$this->nav->_dbi = $dbi;
|
||||||
$this->nav->_storyline = $storyline;
|
$this->nav->_storyline = $storyline;
|
||||||
|
|
||||||
|
$this->assertFalse(wp_cache_get('navigation-1', 'comicpress'));
|
||||||
|
|
||||||
$this->nav->get_post_nav($post);
|
$this->nav->get_post_nav($post);
|
||||||
|
|
||||||
|
$this->assertTrue(wp_cache_get('navigation-1', 'comicpress') !== false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user