summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hamann <michael@content-space.de>2010-11-15 22:16:33 +0100
committerMichael Hamann <michael@content-space.de>2010-11-15 22:16:33 +0100
commite5e503830f067ce7305e22eac58c78c2f4a007d2 (patch)
treeb1e81fba535e7591d6ec6d0de778e1c4dd078d99
parent037b55733d384c194f7554c832f95a5e566c5884 (diff)
downloadrpg-e5e503830f067ce7305e22eac58c78c2f4a007d2.tar.gz
rpg-e5e503830f067ce7305e22eac58c78c2f4a007d2.tar.bz2
Indexer improvement: Only write the words index when needed
This adds a simple boolean variable that tracks if new words have been added. When editing a page in many cases all words have already been used somewhere else or just one or two words are new. Until this change all words indexes read were always written, now only the changed ones are written. The overhead of the new boolean variable should be low.
-rw-r--r--inc/indexer.php5
1 files changed, 4 insertions, 1 deletions
diff --git a/inc/indexer.php b/inc/indexer.php
index a07c3b89a..8174f73d0 100644
--- a/inc/indexer.php
+++ b/inc/indexer.php
@@ -252,6 +252,8 @@ function idx_getPageWords($page){
// arrive here with $words = array(wordlen => array(word => frequency))
+ $word_idx_modified = false;
+
$index = array(); //resulting index
foreach (array_keys($words) as $wlen){
$word_idx = idx_getIndex('w',$wlen);
@@ -260,6 +262,7 @@ function idx_getPageWords($page){
if(!is_int($wid)){
$wid = count($word_idx);
$word_idx[] = "$word\n";
+ $word_idx_modified = true;
}
if(!isset($index[$wlen]))
$index[$wlen] = array();
@@ -267,7 +270,7 @@ function idx_getPageWords($page){
}
// save back word index
- if(!idx_saveIndex('w',$wlen,$word_idx)){
+ if($word_idx_modified && !idx_saveIndex('w',$wlen,$word_idx)){
trigger_error("Failed to write word index", E_USER_ERROR);
return false;
}