Speed optimisation by enabling the posibility of the MySQL fulltext engine

This commit is contained in:
Michael Vogel 2012-05-26 03:21:07 +02:00
parent a71e3134bf
commit 4951210508
5 changed files with 43 additions and 18 deletions

View File

@ -88,3 +88,6 @@ $a->config['system']['itemcache'] = "";
// If enabled, the lockpath is used for a lockfile to check if the poller is running // If enabled, the lockpath is used for a lockfile to check if the poller is running
$a->config['system']['lockpath'] = ""; $a->config['system']['lockpath'] = "";
// If enabled, the MyBB fulltext engine is used
$a->config['system']['use_fulltext_engine'] = true;

View File

@ -976,7 +976,7 @@
$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0); $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
$max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0); $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
//$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0); //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
$start = $page*$count; $start = $page*$count;
//$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false); //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
@ -985,11 +985,19 @@
$myurl = substr($myurl,strpos($myurl,'://')+3); $myurl = substr($myurl,strpos($myurl,'://')+3);
$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl); $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
$diasp_url = str_replace('/profile/','/u/',$myurl); $diasp_url = str_replace('/profile/','/u/',$myurl);
$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` regexp '%s' or `tag` regexp '%s' or tag regexp '%s' )) ",
dbesc($myurl . '$'), if (get_config('system','use_fulltext_engine'))
dbesc($myurl . '\\]'), $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (MATCH(`author-link`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ",
dbesc($diasp_url . '\\]') dbesc(protect_sprintf($myurl)),
); dbesc(protect_sprintf($myurl)),
dbesc(protect_sprintf($diasp_url))
);
else
$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ",
dbesc(protect_sprintf('%' . $myurl)),
dbesc(protect_sprintf('%' . $myurl . '\\]%')),
dbesc(protect_sprintf('%' . $diasp_url . '\\]%'))
);
if ($max_id > 0) if ($max_id > 0)
$sql_extra .= ' AND `item`.`id` <= '.intval($max_id); $sql_extra .= ' AND `item`.`id` <= '.intval($max_id);

View File

@ -77,14 +77,14 @@ class dba {
$this->error = ''; $this->error = '';
//@file_put_contents("/tmp/friendica-db.log", datetime_convert().':'.session_id(). ' Start '.$sql."\n", FILE_APPEND); @file_put_contents("/tmp/friendica-db.log", datetime_convert().':'.session_id(). ' Start '.$sql."\n", FILE_APPEND);
if($this->mysqli) if($this->mysqli)
$result = @$this->db->query($sql); $result = @$this->db->query($sql);
else else
$result = @mysql_query($sql,$this->db); $result = @mysql_query($sql,$this->db);
//@file_put_contents("/tmp/friendica-db.log", datetime_convert().':'.session_id(). ' Stop '."\n", FILE_APPEND); @file_put_contents("/tmp/friendica-db.log", datetime_convert().':'.session_id(). ' Stop '."\n", FILE_APPEND);
if($this->mysqli) { if($this->mysqli) {
if($this->db->errno) if($this->db->errno)

View File

@ -416,11 +416,19 @@ function network_content(&$a, $update = 0) {
$myurl = substr($myurl,strpos($myurl,'://')+3); $myurl = substr($myurl,strpos($myurl,'://')+3);
$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl); $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
$diasp_url = str_replace('/profile/','/u/',$myurl); $diasp_url = str_replace('/profile/','/u/',$myurl);
$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ", if (get_config('system','use_fulltext_engine'))
dbesc(protect_sprintf('%' . $myurl)), $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (MATCH(`author-link`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ",
dbesc(protect_sprintf('%' . $myurl . '\\]%')), dbesc(protect_sprintf($myurl)),
dbesc(protect_sprintf('%' . $diasp_url . '\\]%')) dbesc(protect_sprintf($myurl)),
); dbesc(protect_sprintf($diasp_url))
);
else
$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ",
dbesc(protect_sprintf('%' . $myurl)),
dbesc(protect_sprintf('%' . $myurl . '\\]%')),
dbesc(protect_sprintf('%' . $diasp_url . '\\]%'))
);
} }

View File

@ -109,11 +109,17 @@ function search_content(&$a) {
if(! $search) if(! $search)
return $o; return $o;
if($tag) if (get_config('system','use_fulltext_engine')) {
$sql_extra = sprintf(" AND `item`.`tag` REGEXP '%s' ", dbesc('\\]' . preg_quote($search) . '\\[')); if($tag)
else $sql_extra = sprintf(" AND MATCH (`item`.`tag`) AGAINST ('".'"%s"'."' in boolean mode) ", '#'.preg_quote($search));
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(preg_quote($search))); else
$sql_extra = sprintf(" AND MATCH (`item`.`body`) AGAINST ('".'"%s"'."' in boolean mode) ", dbesc(preg_quote($search)));
} else {
if($tag)
$sql_extra = sprintf(" AND `item`.`tag` REGEXP '%s' ", dbesc('\\]' . preg_quote($search) . '\\['));
else
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(preg_quote($search)));
}