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

Limit queries for pulling add-on options?

Discussion in 'XenForo Development Discussions' started by CaseLogic, Jun 1, 2013.

  1. CaseLogic

    CaseLogic New Member

    I am working on an add-on, and I have set up an option for it in the admincp. However I quickly noticed that these options don't seem to be cached. I have overloaded two model functions, and in each one I am grabbing this option I have set up. When I run the page, I see that my db queries has increased by 2, one for each of the option queries.

    I figured that the options would be cached somewhere so it wouldn't use up a db query to grab it. Do you guys have any recommendations for how I can store this value so it doesn't need to query each time? Can I add it to a global registry or something the first time I grab it and then just check that in the future? What have you guys been doing? Maybe I'm just approaching this the wrong way.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  3. xf_phantom

    xf_phantom Well-Known Member

    Check your debug page. There you'll probably see the 2 new queries. Are they really because of the options?
    Do you use probably custom templates? Or do you do anything else inside the 2 model functions?
     
  4. CaseLogic

    CaseLogic New Member

    Thanks for the responses. I'm modifying the content that gets displayed on the forum view. I have overloaded 2 thread model functions so it changes the conditions of the threads it pulls depending on the set option. I have overloaded the countThreadsInForum routine and the getThreadsInForum routine. The only thing that these routines are doing is pulling the option using the Application::getOption('options') call and modifying the conditions. Then it passes on to the next function as usual. So the only thing in these routines that would generate 2 new db queries is the getOption call.

    Jake, I have set up the options via that page. I added a new option group/option for my addon, and am getting the option via the $options = getOption('options'); $myoption = $options['myoption'] method that I saw in a tutorial somewhere.
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Code:
    $myOption = XenForo_Application::get('options')->myOption;
    
     
  6. CaseLogic

    CaseLogic New Member


    Would that somehow do something different and prevent the query? Seems like it would do the same thing just in one line instead of two.
     

Share This Page