From ea1092eb7c1c685ab86ba3e8bb73e9705dada17a Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Sat, 27 Jul 2013 07:09:05 +0000 Subject: [PATCH] Parse `attrs` before comparing to `attachment.attributes`. Small efficiency gain. Props garyc40. Fixes #24753. git-svn-id: http://core.svn.wordpress.org/trunk@24800 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media-models.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wp-includes/js/media-models.js b/wp-includes/js/media-models.js index 82ffaee661..f501b69fc6 100644 --- a/wp-includes/js/media-models.js +++ b/wp-includes/js/media-models.js @@ -401,7 +401,6 @@ window.wp = window.wp || {}; attachments.on( 'add change remove', this._validateHandler, this ); attachments.on( 'reset', this._validateAllHandler, this ); - this.validateAll( attachments ); return this; }, @@ -487,7 +486,8 @@ window.wp = window.wp || {}; resp = [resp]; return _.map( resp, function( attrs ) { - var id, attachment; + var id, attachment, newAttributes; + if ( attrs instanceof Backbone.Model ) { id = attrs.get( 'id' ); attrs = attrs.attributes; @@ -495,9 +495,11 @@ window.wp = window.wp || {}; id = attrs.id; } - attachment = Attachment.get( attrs.id ); - if ( ! _.isEqual( attachment.attributes, attrs ) ) - attachment.set( attachment.parse( attrs, xhr ) ); + attachment = Attachment.get( id ); + newAttributes = attachment.parse( attrs, xhr ); + + if ( ! _.isEqual( attachment.attributes, newAttributes ) ) + attachment.set( newAttributes ); return attachment; });