Added a better handling of simultaneous updates of the search index.

This commit is contained in:
Loic d'Anterroches 2010-02-14 22:01:46 +01:00
parent 355f9ca05f
commit 96e8f4ae3c

View File

@ -127,9 +127,21 @@ class IDF_Search extends Pluf_Search
if ($ids[$i] === null) { if ($ids[$i] === null) {
$word = new Pluf_Search_Word(); $word = new Pluf_Search_Word();
$word->word = $words_flat[$i]; $word->word = $words_flat[$i];
$word->create(); try {
$ids[$i] = $word->id; $word->create();
$new_words++; $new_words++;
$ids[$i] = $word->id;
} catch (Exception $e) {
// 100% of the time, the word has been created
// by another process in the background.
$r_ids = self::getWordIds(array($word->word));
if ($r_ids[0]) {
$ids[$i] = $r_ids[0];
} else {
// give up for this word
continue;
}
}
} }
if (isset($done[$ids[$i]])) { if (isset($done[$ids[$i]])) {
continue; continue;