1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Does assigning Model variables reduce load?

Discussion in 'XenForo Development Discussions' started by Jaxel, Mar 9, 2011.

  1. Jaxel

    Jaxel Well-Known Member

    I would normally do something like this:
    I see in XenForo, very often:
    $moduleModel = $this->getModelFromCache('EWRporta_Model_Modules');
    Does this methodology reduce load on subsequent entries? Or is it simply for aesthetics?
  2. Shadab

    Shadab Well-Known Member

    No. For all practical purposes, it doesn't make any difference. The model object, once created, is placed in the cache and on each subsequent access, the cached object is returned. Instead of instantiating the object every time.

    But assigning the model object to a separate variable has its advantage too.
    Mainly, code auto-completion in IDEs...
    /* @var $moduleModel EWRporta_Model_Modules */
    $moduleModel = $this->getModelFromCache('EWRporta_Model_Modules');
  3. Mike

    Mike XenForo Developer Staff Member

    What Shadab said, plus it's shorter. :)
  4. Despair

    Despair Active Member

    I don't know XenForo code (or even Zend for that matter), but could you not chain it to be even shorter?
    Maybe not in this case?
  5. Luke F

    Luke F Well-Known Member

    The functions don't return an instance of the model, so no.
    Despair likes this.

Share This Page