Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#13350 closed defect (bug) (fixed)

update_metadata() updates unchanged values

Reported by: ryan's profile ryan Owned by:
Milestone: 3.0.1 Priority: high
Severity: major Version: 3.0
Component: Optimization Keywords: has-patch commit
Focuses: Cc:

Description

update_metadata() generates an UPDATE query even if the value is the same as in the DB. When saving nav menus, for example, this results in many pointless updates.

Attachments (3)

meta.php.2.patch (1.3 KB) - added by jayarjo 15 years ago.
meta.php.patch (1.3 KB) - added by jayarjo 15 years ago.
meta.php.3.patch (521 bytes) - added by shawnparker 15 years ago.
Patch to perform strict === check of old and new metadata instead of loose == check

Download all attachments as: .zip

Change History (12)

#1 @ryan
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [14564]) Don't update meta data when the new value matches the old value. fixes #13350

#2 @jayarjo
15 years ago

  • Keywords has-patch added
  • Priority changed from normal to high
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version set to 3.0

Stumbled upon a defect, which brought me to exactly this piece of code (my plugin stopped working after upgrade to WP 3.0 RC2 from 2.9.2). I store multi-dimensional hybrid array (associative array with some values being indexed arrays) as a post meta, and for some reason == operator fails to check equality of prev and new values (no idea why, I haven't heard of such either, quick googling haven't brought any results, but it fails for sure).

The quick fix for this would probably be doing serialize first followed by equality check.

#3 @jayarjo
15 years ago

Damn, sorry for lame bug report. Tried to be helpful :D Actually old_value would need serialize as well to actually check for equality and not for nothing.

@jayarjo
15 years ago

@jayarjo
15 years ago

#4 @shawnparker
15 years ago

  • Severity changed from normal to major

I just ran in to this as well and the issue for me is that a == check on two arrays will check that all the key/value pairs match, but doesn't care about order. This should probably be a === check to make sure that comparisons are strict.

Will attach patch in a second.

@shawnparker
15 years ago

Patch to perform strict === check of old and new metadata instead of loose == check

#5 @shawnparker
15 years ago

  • Cc shawnparker added

Sorry to be chatty, but I just thought about the strict check and its possibility to damage any data that is loosely delivered to update_postmeta. integer 1 passed in to the function vs. string 1 pulled from the text field in the database could cause issues... maybe some kind of md5 hash check is more in order here?

#6 @nacin
15 years ago

  • Milestone changed from 3.0 to 3.0.1

#7 @nacin
15 years ago

  • Keywords commit added

#8 @ryan
15 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [15390]) Perform strict equality comparison. Props shawnparker. fixes #13350 for 3.0.1

#9 @ryan
15 years ago

[15389] for trunk.

Note: See TracTickets for help on using tickets.