#13350 closed defect (bug) (fixed)
update_metadata() updates unchanged values
Reported by: |
|
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)
Change History (12)
#2
@
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
@
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.
#4
@
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.
#5
@
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?
(In [14564]) Don't update meta data when the new value matches the old value. fixes #13350