[wp-trac] [WordPress Trac] #34304: get_and_update_post_meta for atomic post meta operations

WordPress Trac noreply at wordpress.org
Fri Oct 16 01:23:39 UTC 2015


#34304: get_and_update_post_meta for atomic post meta operations
-----------------------------+------------------------------
 Reporter:  lpghatguy        |       Owner:
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Database         |     Version:  trunk
 Severity:  normal           |  Resolution:
 Keywords:  close            |     Focuses:
-----------------------------+------------------------------
Changes (by rmccue):

 * keywords:   => close


Comment:

 `update_post_meta` has a `$prev_value` parameter that you can pass, which
 gives you a sort of concurrency protection, although it's not locking. For
 this example, you could do:

 {{{
 $value = $old = get_post_meta( $id, 'some_meta_field', true );
 $value++;
 $success = update_post_meta( $id, 'some_meta_field', wp_slash( $value ),
 $old );
 }}}

 (Obviously, this is not exactly equivalent, and locking does have
 benefits.)

 I'd be in favour of a full locking API throughout WP, similar to the
 object cache API, but I think we should go wholesale into it if so. I
 don't see a need for one specifically for post meta though.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34304#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list