Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Issue tags: +Quick fix
FileSize
2.05 KB

This saved about 16ms on a product listing page. Depending on your setup you could save more;)

joelpittet’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: -Quick fix
FileSize
241.22 KB
3.53 KB

Actually this is nicer, saves nearly 100ms.

Not as quick of a fix

joelpittet’s picture

Issue summary: View changes
mglaman’s picture

Issue tags: +Needs manual testing
mglaman’s picture

mglaman’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me. Tests pass on CK2, manually reviewed and found no issues. Moving calls out of loops that don't need to be is always a win.

The last submitted patch, 2: 2595209-2.patch, failed testing.

rszrama’s picture

Status: Reviewed & tested by the community » Needs review

Is this two patches combined in one? Didn't see an explanation for the switch in wrapper usage - and it's kinda funky to see something like this:

  $products = $product;
joelpittet’s picture

@rszrama that is funky, it was to avoid other changes (minimizing the diff of name changes). Don't think it's two patches combined all relate to the performance of that one super large function.

rszrama’s picture

Ok, I'll review. I was originally under the impression the real trick here was moving drupal_get_path() out of the foreach, but I see it's also these other function calls, including not invoking the wrapper in the foreach. I'll probably clean up the variable names before committing.

joelpittet’s picture

Assigned: Unassigned » joelpittet
Status: Needs review » Needs work

@rszrama I'll look at this again, maybe I can unfuddle the variable naming without too much hunk changes.

joelpittet’s picture

Assigned: joelpittet » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs manual testing
FileSize
2.73 KB
4.33 KB

@rszrama the big reason for getting the reference value early is to avoid the count() on the EMW value.

If you feel comfortable committing part and not the other then LMK and I'll split this issue.

Hopefully these changes make it easier to review and not so funky;)

mglaman’s picture

rszrama’s picture

Ok, think I wrapped my head around all the changes. Two observations:

  1. I've further differentiated $products from $product by using $reference_field_value instead of $products. In retrospect, I kinda wished I'd used $default_product throughout here, but this is the simpler fix. (I suppose it's not too late, but that's for a follow-up patch. : )
  2. We can move the check for an empty field value up above the call to entity_metadata_wrapper(), potentially saving more time.
  3. The patch as written introduces a regression where no default product will be selected in the event that all referenced products on an entity are disabled. The current behavior is to still use the normal default product if all referenced products are disabled, so I've reverted to that.

Patch attached.

joelpittet’s picture

@rszrama cool, can you throw up an interdiff please?

mglaman’s picture

FileSize
4.27 KB

Attached interdiff of #13 to #15

torgosPizza’s picture

Status: Needs review » Needs work
torgosPizza’s picture

Status: Needs work » Needs review

C'mon testbot!

joelpittet’s picture

Thanks for the interdiff @mglaman I've went through and it looks good:) @rszrama it's RTBC from me but I'll let a sober second set of eyes on it.

smccabe’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/modules/product_reference/commerce_product_reference.module
@@ -325,6 +325,9 @@ function commerce_product_reference_entity_view($entity, $entity_type, $view_mod
+  // Resolve the product module path now to avoid repeating it in the loop.
+  $product_module_path = drupal_get_path('module', 'commerce_product');

Patch looks good to me, only one tiny nitpick, this comment really only makes sense in the context of this patch, once this is committed, the comment seems unnecessary and slightly confusing, it's not like we explain the scope of every variable we set.

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.