Key caches by blog ID for those doing the multi blog trick.
git-svn-id: https://develop.svn.wordpress.org/trunk@4524 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
44cfe9ceda
commit
f74d084276
@ -481,7 +481,10 @@ function wp_set_link_cats($link_ID = 0, $link_categories = array()) {
|
||||
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->link2cat, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->link2cat.link_id AND category_id = '$cat_id'");
|
||||
$wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'");
|
||||
wp_cache_delete($cat_id, 'category');
|
||||
do_action('edit_category', $cat_id);
|
||||
}
|
||||
|
||||
do_action('edit_link', $link_ID);
|
||||
} // wp_set_link_cats()
|
||||
|
||||
function post_exists($title, $content = '', $post_date = '') {
|
||||
|
@ -60,15 +60,15 @@ function get_category_parents($id, $link = FALSE, $separator = '/', $nicename =
|
||||
}
|
||||
|
||||
function get_the_category($id = false) {
|
||||
global $post, $category_cache;
|
||||
global $post, $category_cache, $blog_id;
|
||||
|
||||
if ( !$id )
|
||||
$id = $post->ID;
|
||||
|
||||
if ( !isset($category_cache[$id]) )
|
||||
if ( !isset($category_cache[$blog_id][$id]) )
|
||||
update_post_category_cache($id);
|
||||
|
||||
$categories = $category_cache[$id];
|
||||
$categories = $category_cache[$blog_id][$id];
|
||||
|
||||
if ( !empty($categories) )
|
||||
sort($categories);
|
||||
@ -140,9 +140,9 @@ function get_the_category_list($separator = '', $parents='') {
|
||||
}
|
||||
|
||||
function in_category($category) { // Check if the current post is in the given category
|
||||
global $category_cache, $post;
|
||||
global $category_cache, $post, $blog_id;
|
||||
|
||||
if ( isset( $category_cache[$post->ID][$category] ) )
|
||||
if ( isset( $category_cache[$blog_id][$post->ID][$category] ) )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
@ -106,10 +106,10 @@ function get_weekstartend($mysqlstring, $start_of_week) {
|
||||
}
|
||||
|
||||
function get_lastpostdate($timezone = 'server') {
|
||||
global $cache_lastpostdate, $pagenow, $wpdb;
|
||||
global $cache_lastpostdate, $pagenow, $wpdb, $blog_id;
|
||||
$add_seconds_blog = get_option('gmt_offset') * 3600;
|
||||
$add_seconds_server = date('Z');
|
||||
if ( !isset($cache_lastpostdate[$timezone]) ) {
|
||||
if ( !isset($cache_lastpostdate[$blog_id][$timezone]) ) {
|
||||
switch(strtolower($timezone)) {
|
||||
case 'gmt':
|
||||
$lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
|
||||
@ -121,18 +121,18 @@ function get_lastpostdate($timezone = 'server') {
|
||||
$lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
|
||||
break;
|
||||
}
|
||||
$cache_lastpostdate[$timezone] = $lastpostdate;
|
||||
$cache_lastpostdate[$blog_id][$timezone] = $lastpostdate;
|
||||
} else {
|
||||
$lastpostdate = $cache_lastpostdate[$timezone];
|
||||
$lastpostdate = $cache_lastpostdate[$blog_id][$timezone];
|
||||
}
|
||||
return $lastpostdate;
|
||||
}
|
||||
|
||||
function get_lastpostmodified($timezone = 'server') {
|
||||
global $cache_lastpostmodified, $pagenow, $wpdb;
|
||||
global $cache_lastpostmodified, $pagenow, $wpdb, $blog_id;
|
||||
$add_seconds_blog = get_option('gmt_offset') * 3600;
|
||||
$add_seconds_server = date('Z');
|
||||
if ( !isset($cache_lastpostmodified[$timezone]) ) {
|
||||
if ( !isset($cache_lastpostmodified[$blog_id][$timezone]) ) {
|
||||
switch(strtolower($timezone)) {
|
||||
case 'gmt':
|
||||
$lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
|
||||
@ -148,9 +148,9 @@ function get_lastpostmodified($timezone = 'server') {
|
||||
if ( $lastpostdate > $lastpostmodified ) {
|
||||
$lastpostmodified = $lastpostdate;
|
||||
}
|
||||
$cache_lastpostmodified[$timezone] = $lastpostmodified;
|
||||
$cache_lastpostmodified[$blog_id][$timezone] = $lastpostmodified;
|
||||
} else {
|
||||
$lastpostmodified = $cache_lastpostmodified[$timezone];
|
||||
$lastpostmodified = $cache_lastpostmodified[$blog_id][$timezone];
|
||||
}
|
||||
return $lastpostmodified;
|
||||
}
|
||||
@ -508,41 +508,41 @@ function is_new_day() {
|
||||
}
|
||||
|
||||
function update_post_cache(&$posts) {
|
||||
global $post_cache;
|
||||
global $post_cache, $blog_id;
|
||||
|
||||
if ( !$posts )
|
||||
return;
|
||||
|
||||
for ($i = 0; $i < count($posts); $i++) {
|
||||
$post_cache[$posts[$i]->ID] = &$posts[$i];
|
||||
$post_cache[$blog_id][$posts[$i]->ID] = &$posts[$i];
|
||||
}
|
||||
}
|
||||
|
||||
function clean_post_cache($id) {
|
||||
global $post_cache;
|
||||
global $post_cache, $blog_id;
|
||||
|
||||
if ( isset( $post_cache[$id] ) )
|
||||
unset( $post_cache[$id] );
|
||||
if ( isset( $post_cache[$blog_id][$id] ) )
|
||||
unset( $post_cache[$blog_id][$id] );
|
||||
}
|
||||
|
||||
function update_page_cache(&$pages) {
|
||||
global $page_cache;
|
||||
global $page_cache, $blog_id;
|
||||
|
||||
if ( !$pages )
|
||||
return;
|
||||
|
||||
for ($i = 0; $i < count($pages); $i++) {
|
||||
$page_cache[$pages[$i]->ID] = &$pages[$i];
|
||||
$page_cache[$blog_id][$pages[$i]->ID] = &$pages[$i];
|
||||
wp_cache_add($pages[$i]->ID, $pages[$i], 'pages');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function clean_page_cache($id) {
|
||||
global $page_cache;
|
||||
global $page_cache, $blog_id;
|
||||
|
||||
if ( isset( $page_cache[$id] ) )
|
||||
unset( $page_cache[$id] );
|
||||
if ( isset( $page_cache[$blog_id][$id] ) )
|
||||
unset( $page_cache[$blog_id][$id] );
|
||||
}
|
||||
|
||||
function update_post_category_cache($post_ids) {
|
||||
@ -578,7 +578,7 @@ function update_post_category_cache($post_ids) {
|
||||
|
||||
function update_post_caches(&$posts) {
|
||||
global $post_cache, $category_cache, $post_meta_cache;
|
||||
global $wpdb;
|
||||
global $wpdb, $blog_id;
|
||||
|
||||
// No point in doing all this work if we didn't match any posts.
|
||||
if ( !$posts )
|
||||
@ -587,7 +587,7 @@ function update_post_caches(&$posts) {
|
||||
// Get the categories for all the posts
|
||||
for ($i = 0; $i < count($posts); $i++) {
|
||||
$post_id_array[] = $posts[$i]->ID;
|
||||
$post_cache[$posts[$i]->ID] = &$posts[$i];
|
||||
$post_cache[$blog_id][$posts[$i]->ID] = &$posts[$i];
|
||||
}
|
||||
|
||||
$post_id_list = implode(',', $post_id_array);
|
||||
@ -598,7 +598,7 @@ function update_post_caches(&$posts) {
|
||||
}
|
||||
|
||||
function update_postmeta_cache($post_id_list = '') {
|
||||
global $wpdb, $post_meta_cache;
|
||||
global $wpdb, $post_meta_cache, $blog_id;
|
||||
|
||||
// We should validate this comma-separated list for the upcoming SQL query
|
||||
$post_id_list = preg_replace('|[^0-9,]|', '', $post_id_list);
|
||||
@ -626,7 +626,7 @@ function update_postmeta_cache($post_id_list = '') {
|
||||
if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id IN($post_id_list) ORDER BY post_id, meta_key", ARRAY_A) ) {
|
||||
// Change from flat structure to hierarchical:
|
||||
if ( !isset($post_meta_cache) )
|
||||
$post_meta_cache = array();
|
||||
$post_meta_cache[$blog_id] = array();
|
||||
|
||||
foreach ($meta_list as $metarow) {
|
||||
$mpid = (int) $metarow['post_id'];
|
||||
@ -634,13 +634,13 @@ function update_postmeta_cache($post_id_list = '') {
|
||||
$mval = $metarow['meta_value'];
|
||||
|
||||
// Force subkeys to be array type:
|
||||
if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) )
|
||||
$post_meta_cache[$mpid] = array();
|
||||
if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) )
|
||||
$post_meta_cache[$mpid]["$mkey"] = array();
|
||||
if ( !isset($post_meta_cache[$blog_id][$mpid]) || !is_array($post_meta_cache[$blog_id][$mpid]) )
|
||||
$post_meta_cache[$blog_id][$mpid] = array();
|
||||
if ( !isset($post_meta_cache[$blog_id][$mpid]["$mkey"]) || !is_array($post_meta_cache[$blog_id][$mpid]["$mkey"]) )
|
||||
$post_meta_cache[$blog_id][$mpid]["$mkey"] = array();
|
||||
|
||||
// Add a value to the current pid/key:
|
||||
$post_meta_cache[$mpid][$mkey][] = $mval;
|
||||
$post_meta_cache[$blog_id][$mpid][$mkey][] = $mval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ function get_attached_file($attachment_id) {
|
||||
}
|
||||
|
||||
function &get_children($args = '', $output = OBJECT) {
|
||||
global $post_cache, $wpdb;
|
||||
global $post_cache, $wpdb, $blog_id;
|
||||
|
||||
if ( empty($args) ) {
|
||||
if ( isset($GLOBALS['post']) )
|
||||
@ -32,7 +32,7 @@ function &get_children($args = '', $output = OBJECT) {
|
||||
|
||||
if ( $children ) {
|
||||
foreach ( $children as $key => $child ) {
|
||||
$post_cache[$child->ID] =& $children[$key];
|
||||
$post_cache[$blog_id][$child->ID] =& $children[$key];
|
||||
$kids[$child->ID] =& $children[$key];
|
||||
}
|
||||
} else {
|
||||
@ -74,7 +74,7 @@ function get_extended($post) {
|
||||
// Retrieves post data given a post ID or post object.
|
||||
// Handles post caching.
|
||||
function &get_post(&$post, $output = OBJECT) {
|
||||
global $post_cache, $wpdb;
|
||||
global $post_cache, $wpdb, $blog_id;
|
||||
|
||||
if ( empty($post) ) {
|
||||
if ( isset($GLOBALS['post']) )
|
||||
@ -84,25 +84,25 @@ function &get_post(&$post, $output = OBJECT) {
|
||||
} elseif ( is_object($post) ) {
|
||||
if ( 'page' == $post->post_type )
|
||||
return get_page($post, $output);
|
||||
if ( !isset($post_cache[$post->ID]) )
|
||||
$post_cache[$post->ID] = &$post;
|
||||
$_post = & $post_cache[$post->ID];
|
||||
if ( !isset($post_cache[$blog_id][$post->ID]) )
|
||||
$post_cache[$blog_id][$post->ID] = &$post;
|
||||
$_post = & $post_cache[$blog_id][$post->ID];
|
||||
} else {
|
||||
if ( $_post = wp_cache_get($post, 'pages') )
|
||||
return get_page($_post, $output);
|
||||
elseif ( isset($post_cache[$post]) )
|
||||
$_post = & $post_cache[$post];
|
||||
elseif ( isset($post_cache[$blog_id][$post]) )
|
||||
$_post = & $post_cache[$blog_id][$post];
|
||||
else {
|
||||
$query = "SELECT * FROM $wpdb->posts WHERE ID = '$post' LIMIT 1";
|
||||
$_post = & $wpdb->get_row($query);
|
||||
if ( 'page' == $_post->post_type )
|
||||
return get_page($_post, $output);
|
||||
$post_cache[$post] = & $_post;
|
||||
$post_cache[$blog_id][$post] = & $_post;
|
||||
}
|
||||
}
|
||||
|
||||
if ( defined('WP_IMPORTING') )
|
||||
unset($post_cache);
|
||||
unset($post_cache[$blog_id]);
|
||||
|
||||
if ( $output == OBJECT ) {
|
||||
return $_post;
|
||||
@ -241,7 +241,7 @@ function get_posts($args) {
|
||||
//
|
||||
|
||||
function add_post_meta($post_id, $key, $value, $unique = false) {
|
||||
global $wpdb, $post_meta_cache;
|
||||
global $wpdb, $post_meta_cache, $blog_id;
|
||||
|
||||
$post_id = (int) $post_id;
|
||||
|
||||
@ -251,7 +251,7 @@ function add_post_meta($post_id, $key, $value, $unique = false) {
|
||||
}
|
||||
}
|
||||
|
||||
$post_meta_cache[$post_id][$key][] = $value;
|
||||
$post_meta_cache[$blog_id][$post_id][$key][] = $value;
|
||||
|
||||
$value = maybe_serialize($value);
|
||||
$value = $wpdb->escape($value);
|
||||
@ -262,7 +262,7 @@ function add_post_meta($post_id, $key, $value, $unique = false) {
|
||||
}
|
||||
|
||||
function delete_post_meta($post_id, $key, $value = '') {
|
||||
global $wpdb, $post_meta_cache;
|
||||
global $wpdb, $post_meta_cache, $blog_id;
|
||||
|
||||
$post_id = (int) $post_id;
|
||||
|
||||
@ -277,40 +277,48 @@ function delete_post_meta($post_id, $key, $value = '') {
|
||||
|
||||
if ( empty($value) ) {
|
||||
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'");
|
||||
unset($post_meta_cache[$post_id][$key]);
|
||||
unset($post_meta_cache[$blog_id][$post_id][$key]);
|
||||
} else {
|
||||
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'");
|
||||
$cache_key = $post_meta_cache[$post_id][$key];
|
||||
$cache_key = $post_meta_cache[$blog_id][$post_id][$key];
|
||||
if ($cache_key) foreach ( $cache_key as $index => $data )
|
||||
if ( $data == $value )
|
||||
unset($post_meta_cache[$post_id][$key][$index]);
|
||||
unset($post_meta_cache[$blog_id][$post_id][$key][$index]);
|
||||
}
|
||||
|
||||
unset($post_meta_cache[$post_id][$key]);
|
||||
unset($post_meta_cache[$blog_id][$post_id][$key]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function get_post_meta($post_id, $key, $single = false) {
|
||||
global $wpdb, $post_meta_cache;
|
||||
global $wpdb, $post_meta_cache, $blog_id;
|
||||
|
||||
$post_id = (int) $post_id;
|
||||
|
||||
if ( !isset($post_meta_cache[$post_id]) )
|
||||
if ( isset($post_meta_cache[$blog_id][$post_id][$key]) ) {
|
||||
if ( $single ) {
|
||||
return maybe_unserialize( $post_meta_cache[$blog_id][$post_id][$key][0] );
|
||||
} else {
|
||||
return maybe_unserialize( $post_meta_cache[$blog_id][$post_id][$key] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !isset($post_meta_cache[$blog_id][$post_id]) )
|
||||
update_postmeta_cache($post_id);
|
||||
|
||||
if ( $single ) {
|
||||
if ( isset($post_meta_cache[$post_id][$key][0]) )
|
||||
return maybe_unserialize($post_meta_cache[$post_id][$key][0]);
|
||||
if ( isset($post_meta_cache[$blog_id][$post_id][$key][0]) )
|
||||
return maybe_unserialize($post_meta_cache[$blog_id][$post_id][$key][0]);
|
||||
else
|
||||
return '';
|
||||
} else {
|
||||
return maybe_unserialize($post_meta_cache[$post_id][$key]);
|
||||
return maybe_unserialize($post_meta_cache[$blog_id][$post_id][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
function update_post_meta($post_id, $key, $value, $prev_value = '') {
|
||||
global $wpdb, $post_meta_cache;
|
||||
global $wpdb, $post_meta_cache, $blog_id;
|
||||
|
||||
$post_id = (int) $post_id;
|
||||
|
||||
@ -328,17 +336,17 @@ function update_post_meta($post_id, $key, $value, $prev_value = '') {
|
||||
|
||||
if ( empty($prev_value) ) {
|
||||
$wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id'");
|
||||
$cache_key = $post_meta_cache[$post_id][$key];
|
||||
$cache_key = $post_meta_cache[$blog_id][$post_id][$key];
|
||||
if ( !empty($cache_key) )
|
||||
foreach ($cache_key as $index => $data)
|
||||
$post_meta_cache[$post_id][$key][$index] = $original_value;
|
||||
$post_meta_cache[$blog_id][$post_id][$key][$index] = $original_value;
|
||||
} else {
|
||||
$wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id' AND meta_value = '$prev_value'");
|
||||
$cache_key = $post_meta_cache[$post_id][$key];
|
||||
$cache_key = $post_meta_cache[$blog_id][$post_id][$key];
|
||||
if ( !empty($cache_key) )
|
||||
foreach ($cache_key as $index => $data)
|
||||
if ( $data == $original_prev )
|
||||
$post_meta_cache[$post_id][$key][$index] = $original_value;
|
||||
$post_meta_cache[$blog_id][$post_id][$key][$index] = $original_value;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -346,17 +354,17 @@ function update_post_meta($post_id, $key, $value, $prev_value = '') {
|
||||
|
||||
|
||||
function get_post_custom($post_id = 0) {
|
||||
global $id, $post_meta_cache, $wpdb;
|
||||
global $id, $post_meta_cache, $wpdb, $blog_id;
|
||||
|
||||
if ( !$post_id )
|
||||
$post_id = $id;
|
||||
|
||||
$post_id = (int) $post_id;
|
||||
|
||||
if ( !isset($post_meta_cache[$post_id]) )
|
||||
if ( !isset($post_meta_cache[$blog_id][$post_id]) )
|
||||
update_postmeta_cache($post_id);
|
||||
|
||||
return $post_meta_cache[$post_id];
|
||||
return $post_meta_cache[$blog_id][$post_id];
|
||||
}
|
||||
|
||||
function get_post_custom_keys( $post_id = 0 ) {
|
||||
@ -796,7 +804,10 @@ function wp_set_post_categories($post_ID = 0, $post_categories = array()) {
|
||||
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_status = 'publish' AND post_type = 'post' AND category_id = '$cat_id'");
|
||||
$wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
|
||||
wp_cache_delete($cat_id, 'category');
|
||||
do_action('edit_category', $cat_id);
|
||||
}
|
||||
|
||||
do_action('edit_post', $post_ID);
|
||||
} // wp_set_post_categories()
|
||||
|
||||
//
|
||||
@ -895,7 +906,7 @@ function get_all_page_ids() {
|
||||
// Retrieves page data given a page ID or page object.
|
||||
// Handles page caching.
|
||||
function &get_page(&$page, $output = OBJECT) {
|
||||
global $wpdb;
|
||||
global $wpdb, $blog_id;
|
||||
|
||||
if ( empty($page) ) {
|
||||
if ( isset($GLOBALS['page']) ) {
|
||||
@ -913,7 +924,7 @@ function &get_page(&$page, $output = OBJECT) {
|
||||
if ( isset($GLOBALS['page']->ID) && ($page == $GLOBALS['page']->ID) ) {
|
||||
$_page = & $GLOBALS['page'];
|
||||
wp_cache_add($_page->ID, $_page, 'pages');
|
||||
} elseif ( !isset($_page) && $_page == $GLOBALS['post_cache'][$page] ) {
|
||||
} elseif ( !isset($_page) && $_page == $GLOBALS['post_cache'][$blog_id][$page] ) {
|
||||
return get_post($page, $output);
|
||||
} elseif ( isset($_page) && $_page == wp_cache_get($page, 'pages') ) {
|
||||
// Got it.
|
||||
@ -979,10 +990,10 @@ function get_page_by_title($page_title, $output = OBJECT) {
|
||||
}
|
||||
|
||||
function &get_page_children($page_id, $pages) {
|
||||
global $page_cache;
|
||||
global $page_cache, $blog_id;
|
||||
|
||||
if ( empty($pages) )
|
||||
$pages = &$page_cache;
|
||||
$pages = &$page_cache[$blog_id];
|
||||
|
||||
$page_list = array();
|
||||
foreach ( $pages as $page ) {
|
||||
|
Loading…
Reference in New Issue
Block a user