Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
332 views
in Q2A Core by
edited by

For search module this function is triggered whenever user searches on q2a website:

qa_get_search_results($query, $start, $count, $userid, $absoluteurls, $fullcontent)

Inside the above function the two main DB events occurs as shown below:

qa_get_search_results($query, $start, $count, $userid, $absoluteurls, $fullcontent)

{

Ist DB Event:

// Get the results 

$results = $module->process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent);

2nd DB Event: 

// Perform the appropriate database queries 

list($postidfull, $postidtype, $postidquestion, $pageidpage) = qa_db_select_with_pending( 

count($keypostidgetfull) ? qa_db_posts_selectspec($userid, array_keys($keypostidgetfull), $fullcontent) : null, 

count($keypostidgettype) ? qa_db_posts_basetype_selectspec(array_keys($keypostidgettype)) : null, 

count($keypostidgetquestion) ? qa_db_posts_to_qs_selectspec($userid, array_keys($keypostidgetquestion), $fullcontent) : null, 

count($keypageidgetpage) ? qa_db_pages_selectspec(null, array_keys($keypageidgetpage)) : null );

}

I am already handling 1st DB event using elastic search, so there is no DB hit in this case and here I saving MYSQL SERVER RESOURCES.

But still, in the 2nd DB Event, there are a lot of conditions applied in database queries which are creating a lot of DB connections if more users started searching on-site which leads to high CPU resource consumption and make the process too slow.

Please help me with how can I optimize in the 2nd DB Event.

Q2A version: 1.8.6

Please log in or register to answer this question.

...