Make WordPress Core

Changeset 4373


Ignore:
Timestamp:
10/11/2006 09:19:10 AM (18 years ago)
Author:
markjaquith
Message:

Post meta caching fix by mdawaffe. fixes #3229

Location:
branches/2.0/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0/wp-includes/functions.php

    r4344 r4373  
    422422    global $wpdb, $post_meta_cache;
    423423
     424    $post_id = (int) $post_id;
     425
    424426    if ( $unique ) {
    425         if ( $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key
    426 = '$key' AND post_id = '$post_id'") ) {
     427        if ( $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = '$key' AND post_id = '$post_id'") ) {
    427428            return false;
    428429        }
     
    435436    $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_id','$key','$value')");
    436437
    437     $post_meta_cache['$post_id'][$key][] = $original;
     438    $post_meta_cache[$post_id][$key][] = $original;
    438439
    439440    return true;
     
    443444    global $wpdb, $post_meta_cache;
    444445
     446    $post_id = (int) $post_id;
     447
    445448    if ( empty($value) ) {
    446         $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE
    447 post_id = '$post_id' AND meta_key = '$key'");
    448     } else {
    449         $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE
    450 post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'");
     449        $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'");
     450    } else {
     451        $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'");
    451452    }
    452453
     
    455456
    456457    if ( empty($value) ) {
    457         $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id'
    458 AND meta_key = '$key'");
    459         unset($post_meta_cache['$post_id'][$key]);
    460     } else {
    461         $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id'
    462 AND meta_key = '$key' AND meta_value = '$value'");
    463         $cache_key = $post_meta_cache['$post_id'][$key];
     458        $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'");
     459        unset($post_meta_cache[$post_id][$key]);
     460    } else {
     461        $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'");
     462        $cache_key = $post_meta_cache[$post_id][$key];
    464463        if ($cache_key) foreach ( $cache_key as $index => $data )
    465464            if ( $data == $value )
    466                 unset($post_meta_cache['$post_id'][$key][$index]);
    467     }
    468 
    469     unset($post_meta_cache['$post_id'][$key]);
     465                unset($post_meta_cache[$post_id][$key][$index]);
     466    }
     467
     468    unset($post_meta_cache[$post_id][$key]);
    470469
    471470    return true;
     
    474473function get_post_meta($post_id, $key, $single = false) {
    475474    global $wpdb, $post_meta_cache;
     475
     476    $post_id = (int) $post_id;
    476477
    477478    if ( isset($post_meta_cache[$post_id][$key]) ) {
     
    508509    global $wpdb, $post_meta_cache;
    509510
     511    $post_id = (int) $post_id;
     512
    510513    $original_value = $value;
    511514    if ( is_array($value) || is_object($value) )
     
    516519        $prev_value = $wpdb->escape(serialize($prev_value));
    517520
    518     if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key
    519 = '$key' AND post_id = '$post_id'") ) {
     521    if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = '$key' AND post_id = '$post_id'") ) {
    520522        return false;
    521523    }
    522524
    523525    if ( empty($prev_value) ) {
    524         $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE
    525 meta_key = '$key' AND post_id = '$post_id'");
    526         $cache_key = $post_meta_cache['$post_id'][$key];
     526        $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id'");
     527        $cache_key = $post_meta_cache[$post_id][$key];
    527528        if ( !empty($cache_key) )
    528529            foreach ($cache_key as $index => $data)
    529                 $post_meta_cache['$post_id'][$key][$index] = $original_value;
    530     } else {
    531         $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE
    532 meta_key = '$key' AND post_id = '$post_id' AND meta_value = '$prev_value'");
    533         $cache_key = $post_meta_cache['$post_id'][$key];
     530                $post_meta_cache[$post_id][$key][$index] = $original_value;
     531    } else {
     532        $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id' AND meta_value = '$prev_value'");
     533        $cache_key = $post_meta_cache[$post_id][$key];
    534534        if ( !empty($cache_key) )
    535535            foreach ($cache_key as $index => $data)
    536536                if ( $data == $original_prev )
    537                     $post_meta_cache['$post_id'][$key][$index] = $original_value;
     537                    $post_meta_cache[$post_id][$key][$index] = $original_value;
    538538    }
    539539
     
    14451445        $post_meta_cache = array();
    14461446        foreach ($meta_list as $metarow) {
    1447             $mpid = $metarow['post_id'];
     1447            $mpid = (int) $metarow['post_id'];
    14481448            $mkey = $metarow['meta_key'];
    14491449            $mval = $metarow['meta_value'];
  • branches/2.0/wp-includes/template-functions-post.php

    r4368 r4373  
    201201        $post_id = $id;
    202202
     203    $post_id = (int) $post_id;
     204
    203205    if ( isset($post_meta_cache[$post_id]) )
    204206        return $post_meta_cache[$post_id];
     
    208210        $post_meta_cache = array();
    209211        foreach ( $meta_list as $metarow ) {
    210             $mpid = $metarow['post_id'];
     212            $mpid = (int) $metarow['post_id'];
    211213            $mkey = $metarow['meta_key'];
    212214            $mval = $metarow['meta_value'];
     
    257259// this will probably change at some point...
    258260function the_meta() {
    259     global $id, $post_meta_cache;
     261    global $id;
    260262
    261263    if ( $keys = get_post_custom_keys() ) {
Note: See TracChangeset for help on using the changeset viewer.