function uc_catalog_buy_it_now_form_validate($form, &$form_state) {
  if (module_exists('uc_attribute')) {

    $node = node_load($form_state['values']['nid']); //not needed at all!

    $attributes = uc_product_get_attributes($node->nid); //nid is already in $form_state
    if (!empty($attributes)) {
      drupal_set_message(t('This product has options that need to be selected before purchase. Please select them in the form below.'), 'error');
      drupal_goto('node/'. $form_state['values']['nid']);
    }
  }
}

I've also notice there are lot of using node_load() in such simple tasks for example uc_product_is_product with 'nid' as an argument does that huge task just to check single type field. This can be done much faster, for example we can check if the following query is not empty - 'select nid from uc_products where nid='

Ubercart can be much faster...

CommentFileSizeAuthor
#3 959840.patch793 bytestr

Comments

sleamey’s picture

Priority: Minor » Normal
Issue tags: +Performance
sleamey’s picture

tr’s picture

Version: 6.x-2.4 » 6.x-2.x-dev
Status: Active » Needs review
Issue tags: -Performance
StatusFileSize
new793 bytes

I've investigated this situation and I think there should be no consequences to removing the node_load(). The Ubercart test cases all still pass with this change. Test coverage isn't fantastic, so that's not sufficient, but at least it's a start.

Patch attached. I'd like to see some reviews before this goes in to make sure there aren't any unintended side-effects.

Same patch is needed for Ubercart 7.x-3.x ...

tr’s picture

(ignore the .ods - attached by accident.)

longwave’s picture

Seems reasonable, and I can't see why it would have side effects. Ideally this code should be moved into uc_attribute as well, there should be no reason to have module_exists() calls here.

tr’s picture

Status: Needs review » Fixed

Committed to 6.x-2.x-dev and 7.x-3.x-dev.

Status: Fixed » Closed (fixed)

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