From e5e503830f067ce7305e22eac58c78c2f4a007d2 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Mon, 15 Nov 2010 22:16:33 +0100 Subject: 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. --- inc/indexer.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3