From 726eaf7a78b0305f5acd1a6e2ac256f30d97d7b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Fri, 19 Feb 2010 18:06:34 +0100 Subject: [PATCH] Moves user_reindex to Profile. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- bin/search.rebuild_db.php | 3 +-- classes/profile.php | 32 ++++++++++++++++++++++++++++++++ include/name.func.inc.php | 3 +-- include/user.func.inc.php | 39 --------------------------------------- modules/register.php | 8 ++------ 5 files changed, 36 insertions(+), 49 deletions(-) diff --git a/bin/search.rebuild_db.php b/bin/search.rebuild_db.php index d506fa4..966287e 100755 --- a/bin/search.rebuild_db.php +++ b/bin/search.rebuild_db.php @@ -21,7 +21,6 @@ ***************************************************************************/ require('./connect.db.inc.php'); -require('user.func.inc.php'); ini_set('memory_limit', "16M"); $globals->debug = 0; // Do not store backtraces @@ -31,7 +30,7 @@ $res = XDB::iterRow("SELECT user_id $i = 0; $n = $res->total(); while ($uid = $res->next()->fetchOneCell()) { - user_reindex($uid); + Profile::rebuildSearchTokens($uid); printf("\r%u / %u", ++$i, $n); } diff --git a/classes/profile.php b/classes/profile.php index 8136f0b..ad80d8a 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -578,6 +578,38 @@ class Profile return $table[$type]; } } + + public static function rebuildSearchTokens($pid) + { + XDB::execute('DELETE FROM search_name + WHERE uid = {?}', + $pid); + $keys = XDB::iterator("SELECT CONCAT(n.particle, n.name) AS name, e.score, + FIND_IN_SET('public', e.flags) AS public + FROM profile_name AS n + INNER JOIN profile_name_enum AS e ON (n.typeid = e.id) + WHERE n.pid = {?}", + $pid); + + foreach ($keys as $i => $key) { + if ($key['name'] == '') { + continue; + } + $toks = preg_split('/[ \'\-]+/', $key['name']); + $token = ''; + $first = 5; + while ($toks) { + $token = strtolower(replace_accent(array_pop($toks) . $token)); + $score = ($toks ? 0 : 10 + $first) * ($key['score'] / 10); + XDB::execute('REPLACE INTO search_name (token, uid, soundex, score, flags) + VALUES ({?}, {?}, {?}, {?}, {?})', + $token, $uid, soundex_fr($token), $score, $key['public']); + $first = 0; + } + } + + + } } /** Iterator over a set of Profiles diff --git a/include/name.func.inc.php b/include/name.func.inc.php index 663aef9..f1f3f68 100644 --- a/include/name.func.inc.php +++ b/include/name.func.inc.php @@ -282,8 +282,7 @@ function set_alias_names(&$sn_new, $sn_old, $update_new = false, $new_alias = nu VALUES ({?}, 'alias', 'usage', {?})", $new_alias, S::i('uid')); } - require_once('user.func.inc.php'); - user_reindex(S::i('uid')); + Profile::rebuildSearchTokens(S::i('uid')); return $has_new; } diff --git a/include/user.func.inc.php b/include/user.func.inc.php index 487507a..ef0e133 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -84,45 +84,6 @@ function user_clear_all_subs($user_id, $really_del=true) } // }}} -// {{{ function _user_reindex - -function _user_reindex($uid, $keys) -{ - foreach ($keys as $i => $key) { - if ($key['name'] == '') { - continue; - } - $toks = preg_split('/[ \'\-]+/', $key['name']); - $token = ""; - $first = 5; - while ($toks) { - $token = strtolower(replace_accent(array_pop($toks) . $token)); - $score = ($toks ? 0 : 10 + $first) * ($key['score'] / 10); - XDB::execute("REPLACE INTO search_name (token, uid, soundex, score, flags) - VALUES ({?}, {?}, {?}, {?}, {?})", - $token, $uid, soundex_fr($token), $score, $key['public']); - $first = 0; - } - } -} - -// }}} -// {{{ function user_reindex - -function user_reindex($uid) { - XDB::execute("DELETE FROM search_name - WHERE uid = {?}", - $uid); - $res = XDB::iterator("SELECT CONCAT(n.particle, n.name) AS name, e.score, - FIND_IN_SET('public', e.flags) AS public - FROM profile_name AS n - INNER JOIN profile_name_enum AS e ON (n.typeid = e.id) - WHERE n.pid = {?}", - $uid); - _user_reindex($uid, $res); -} - -// }}} // {{{ function get_X_mat function get_X_mat($ourmat) { diff --git a/modules/register.php b/modules/register.php index b3885fb..73c9fa7 100644 --- a/modules/register.php +++ b/modules/register.php @@ -255,8 +255,6 @@ class RegisterModule extends PLModule return PL_FORBIDDEN; } - require_once('user.func.inc.php'); - // Retrieve the pre-registration information using the url-provided // authentication token. if ($hash) { @@ -325,7 +323,7 @@ class RegisterModule extends PLModule } // Add the registration email address as first and only redirection. - require_once('emails.inc.php'); + require_once 'emails.inc.php'; $user = User::getSilent($uid); $redirect = new Redirect($user); $redirect->add_email($email); @@ -342,7 +340,6 @@ class RegisterModule extends PLModule AXLetter::subscribe(S::user()->id()); break; case 'imap': - require_once 'emails.inc.php'; $user = S::user(); $storage = new EmailStorage($user, 'imap'); $storage->activate(); @@ -378,8 +375,7 @@ class RegisterModule extends PLModule $mymail->send(); // Index the user, to allow her to appear in searches. - require_once('user.func.inc.php'); - user_reindex($uid); + Profile::rebuildSearchTokens($uid); // Notify other users which were watching for her arrival. require_once 'notifs.inc.php'; -- 2.1.4