Пример #1
0
 /**
  * Retrieve info for user lists to prevent multiple queries by get_userdata()
  *
  * @since 3.0.0
  *
  * @param array $user_ids User ID numbers list
  */
 function cache_users($user_ids)
 {
     global $wpdb;
     $clean = _get_non_cached_ids($user_ids, 'users');
     if (empty($clean)) {
         return;
     }
     $list = implode(',', $clean);
     $users = $wpdb->get_results("SELECT * FROM {$wpdb->users} WHERE ID IN ({$list})");
     $ids = array();
     foreach ($users as $user) {
         update_user_caches($user);
         $ids[] = $user->ID;
     }
     update_meta_cache('user', $ids);
 }
Пример #2
0
/**
 * Adds any posts from the given ids to the cache that do not already exist in cache
 *
 * @since 3.4.0
 * @access private
 *
 * @see update_post_caches()
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $ids               ID list.
 * @param bool  $update_term_cache Optional. Whether to update the term cache. Default true.
 * @param bool  $update_meta_cache Optional. Whether to update the meta cache. Default true.
 */
function _prime_post_caches($ids, $update_term_cache = true, $update_meta_cache = true)
{
    global $wpdb;
    $non_cached_ids = _get_non_cached_ids($ids, 'posts');
    if (!empty($non_cached_ids)) {
        $fresh_posts = $wpdb->get_results(sprintf("SELECT {$wpdb->posts}.* FROM {$wpdb->posts} WHERE ID IN (%s)", join(",", $non_cached_ids)));
        update_post_caches($fresh_posts, 'any', $update_term_cache, $update_meta_cache);
    }
}
Пример #3
0
/**
 * Adds any comments from the given IDs to the cache that do not already exist in cache.
 *
 * @since 4.4.0
 * @access private
 *
 * @see update_comment_cache()
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $comment_ids       Array of comment IDs.
 * @param bool  $update_meta_cache Optional. Whether to update the meta cache. Default true.
 */
function _prime_comment_caches($comment_ids, $update_meta_cache = true)
{
    global $wpdb;
    $non_cached_ids = _get_non_cached_ids($comment_ids, 'comment');
    if (!empty($non_cached_ids)) {
        $fresh_comments = $wpdb->get_results(sprintf("SELECT {$wpdb->comments}.* FROM {$wpdb->comments} WHERE comment_ID IN (%s)", join(",", array_map('intval', $non_cached_ids))));
        update_comment_cache($fresh_comments, $update_meta_cache);
    }
}
Пример #4
0
/**
 * Adds any terms from the given IDs to the cache that do not already exist in cache.
 *
 * @since 4.6.0
 * @access private
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $term_ids          Array of term IDs.
 * @param bool  $update_meta_cache Optional. Whether to update the meta cache. Default true.
 */
function _prime_term_caches($term_ids, $update_meta_cache = true)
{
    global $wpdb;
    $non_cached_ids = _get_non_cached_ids($term_ids, 'terms');
    if (!empty($non_cached_ids)) {
        $fresh_terms = $wpdb->get_results(sprintf("SELECT t.*, tt.* FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE t.term_id IN (%s)", join(",", array_map('intval', $non_cached_ids))));
        update_term_cache($fresh_terms, $update_meta_cache);
        if ($update_meta_cache) {
            update_termmeta_cache($non_cached_ids);
        }
    }
}
Пример #5
0
 /**
  * Load all posts with one query, to prime the cache
  *
  * @see get_post()
  * @since 1.0.0
  *
  * @param array $all_post_ids List of Post IDs
  * @param bool $update_meta_cache Whether to update the Post Meta Cache (for table options and visibility)
  */
 public function load_posts(array $all_post_ids, $update_meta_cache = true)
 {
     global $wpdb;
     // Split post loading, to save memory
     $offset = 0;
     $length = 100;
     // 100 posts at a time
     $number_of_posts = count($all_post_ids);
     while ($offset < $number_of_posts) {
         $post_ids = array_slice($all_post_ids, $offset, $length);
         $post_ids = _get_non_cached_ids($post_ids, 'posts');
         // Don't load posts that are in the cache already
         if (!empty($post_ids)) {
             $post_ids_list = implode(',', $post_ids);
             $posts = $wpdb->get_results("SELECT {$wpdb->posts}.* FROM {$wpdb->posts} WHERE ID IN ({$post_ids_list})");
             update_post_cache($posts);
             if ($update_meta_cache) {
                 update_meta_cache('post', $post_ids);
                 // get all post meta data for all table posts, @see get_post_meta()
             }
         }
         $offset += $length;
         // next array_slice() $offset
     }
 }
Пример #6
0
/**
 * Adds any networks from the given IDs to the cache that do not already exist in cache.
 *
 * @since 4.6.0
 * @access private
 *
 * @see update_network_cache()
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $network_ids Array of network IDs.
 */
function _prime_network_caches($network_ids)
{
    global $wpdb;
    $non_cached_ids = _get_non_cached_ids($network_ids, 'networks');
    if (!empty($non_cached_ids)) {
        $fresh_networks = $wpdb->get_results(sprintf("SELECT {$wpdb->site}.* FROM {$wpdb->site} WHERE id IN (%s)", join(",", array_map('intval', $non_cached_ids))));
        update_network_cache($fresh_networks);
    }
}
Пример #7
0
/**
 * Adds any sites from the given ids to the cache that do not already exist in cache.
 *
 * @since 4.6.0
 * @access private
 *
 * @see update_site_cache()
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $ids ID list.
 */
function _prime_site_caches($ids)
{
    global $wpdb;
    $non_cached_ids = _get_non_cached_ids($ids, 'sites');
    if (!empty($non_cached_ids)) {
        $fresh_sites = $wpdb->get_results(sprintf("SELECT * FROM {$wpdb->blogs} WHERE blog_id IN (%s)", join(",", array_map('intval', $non_cached_ids))));
        update_site_cache($fresh_sites);
    }
}