CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • Report and Search UI Discussion (Moderators: CiviTeacher.com, TwoMice) »
  • Custom search - My SQL query is getting run twice
Pages: [1]

Author Topic: Custom search - My SQL query is getting run twice  (Read 1820 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Custom search - My SQL query is getting run twice
November 24, 2013, 07:34:52 am
I have a custom search that I am working to optimize the speed. What I am noticing is that after the user clicks "submit", my SQL is executed twice.      Also, I am using "mytop" to monitor the queries, and I noticed there that my SQL seems to be run a third time within the context of " INSERT INTO civicrm_prevnext_cache ( entity_table, entity_id1, entity_id2, cacheKey, data   ..."  before the results are shown to the end-user.

So if the SQL takes X seconds to run, the user does not see any results until after X times 3 seconds.

Any ideas on how to get the SQL to be executed just once?
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Custom search - My SQL query is getting run twice
November 24, 2013, 08:24:36 am

make sure your custom search is not executing the query in the pre-process code

u might want to check the behavior of some shipped custom searches to see if they exhibit the same behavior

note that variations of the query are run for - count, alphabetical pager, listing, prev_next cache etc

i think mysql caching if enabled might avoid the performance impact of issuing the same query

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Custom search - My SQL query is getting run twice
November 24, 2013, 09:30:27 am
I found the source of the query being run one of the extra times: It was in the "count" function.   The custom searches that ship with CiviCRM share this behavior. (At least the few I checked. )

I read this article on enabling MySQL query caching: http://www.docplanet.org/mysql/mysql-query-cache-in-depth/ and am not sure if this is the best approach.     What would you suggest changing within CiviCRM itself to avoid rerunning the SQL for a custom search?   

I was looking at the "count" function, which does the following:
Code: [Select]
$sql = $this->all( );
           
           $dao = CRM_Core_DAO::executeQuery( $sql,
                                             CRM_Core_DAO::$_nullArray );
           return $dao->N;

Any ideas on how I can eliminate this extra execution of the SQL, but still get the count? ( Also, on eliminating the extra execution for the third call for the prev_next cache )


Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • Report and Search UI Discussion (Moderators: CiviTeacher.com, TwoMice) »
  • Custom search - My SQL query is getting run twice

This forum was archived on 2017-11-26.