[buddypress-trac] [BuddyPress] #4018: @mentions (slow query)

buddypress-trac at lists.automattic.com buddypress-trac at lists.automattic.com
Sat Feb 18 19:07:50 UTC 2012


#4018: @mentions (slow query)
-------------------------+------------------------------
 Reporter:  webraket     |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Activity     |     Version:  1.5.3
 Severity:  major        |  Resolution:
 Keywords:               |
-------------------------+------------------------------
Changes (by webraket):

 * component:  Core => Activity


Comment:

 I added a fulltext index to bp_activity.content and wrote a small plugin.
 Query's now take less than 0,01 sec

 {{{
 <?php
 function bp_activity_fulltext_search($q){

         //check if query contains LIKE operator
         if(strpos($q,"WHERE a.content LIKE '%")!==FALSE){

                 global $wpdb;

                 //extract search_terms (escape again just to be sure)
                 $aParts = explode("%",$q);
                 $search_terms = $wpdb->escape($aParts[1]);

                 //modify query
                 $q = preg_replace("/WHERE /", "WHERE MATCH(`content`)
 AGAINST('".$search_terms."') AND ", $q, 1);

         }
         return $q;

 }
 add_filter('bp_activity_get_user_join_filter',
 'bp_activity_fulltext_search');
 add_filter('bp_activity_total_activities_sql',
 'bp_activity_fulltext_search');
 ?>
 }}}

 Still think this should be fixed in core...

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/4018#comment:2>
BuddyPress <http://buddypress.org/>
BuddyPress


More information about the buddypress-trac mailing list