From b1720e5c647585ac14f86e6080b54c932cac9bee Mon Sep 17 00:00:00 2001 From: Michael Hamann <michael@content-space.de> Date: Sun, 5 May 2013 21:09:40 +0200 Subject: [PATCH] Indexer: Remove broken and dead readdircache code FS#2771 The code that is removed in this commit has either never been used (listIndexLenghts) or was completely broken (cacheIndexDir) and was introduced in the indexer rewrite in 2010. The idea of the rewrite was to update the readdir cache after every index change instead of on demand. What the code actually did was removing every updated index from the cache as it used a wrong if condition. Simply fixing the condition wouldn't fix the problem as then only updated indexes would be added to the cache and furthermore the rewrite simply ignored the readdircache setting. For now the safest solution seems to be removing the code. It could be added again in a changed form in a future version. --- inc/indexer.php | 78 +------------------------------------------------ 1 file changed, 1 insertion(+), 77 deletions(-) diff --git a/inc/indexer.php b/inc/indexer.php index fdb147334..2f3ab25dc 100644 --- a/inc/indexer.php +++ b/inc/indexer.php @@ -1073,8 +1073,6 @@ class Doku_Indexer { if (isset($conf['fperm'])) chmod($fn.'.tmp', $conf['fperm']); io_rename($fn.'.tmp', $fn.'.idx'); - if ($suffix !== '') - $this->cacheIndexDir($idx, $suffix, empty($lines)); return true; } @@ -1140,8 +1138,6 @@ class Doku_Indexer { if (isset($conf['fperm'])) chmod($fn.'.tmp', $conf['fperm']); io_rename($fn.'.tmp', $fn.'.idx'); - if ($suffix !== '') - $this->cacheIndexDir($idx, $suffix); return true; } @@ -1168,40 +1164,6 @@ class Doku_Indexer { return $id; } - /** - * @param string $idx The index file which should be added to the key. - * @param string $suffix The suffix of the file - * @param bool $delete Unused - */ - protected function cacheIndexDir($idx, $suffix, $delete=false) { - global $conf; - if ($idx == 'i') - $cachename = $conf['indexdir'].'/lengths'; - else - $cachename = $conf['indexdir'].'/'.$idx.'lengths'; - $lengths = @file($cachename.'.idx', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - if ($lengths === false) $lengths = array(); - $old = array_search((string)$suffix, $lengths); - if (empty($lines)) { - if ($old === false) return; - unset($lengths[$old]); - } else { - if ($old !== false) return; - $lengths[] = $suffix; - sort($lengths); - } - $fh = @fopen($cachename.'.tmp', 'w'); - if (!$fh) { - trigger_error("Failed to write index cache", E_USER_ERROR); - return; - } - @fwrite($fh, implode("\n", $lengths)); - @fclose($fh); - if (isset($conf['fperm'])) - chmod($cachename.'.tmp', $conf['fperm']); - io_rename($cachename.'.tmp', $cachename.'.idx'); - } - /** * Get the list of lengths indexed in the wiki. * @@ -1211,45 +1173,7 @@ class Doku_Indexer { * @author YoBoY <yoboy.leguesh@gmail.com> */ protected function listIndexLengths() { - global $conf; - $cachename = $conf['indexdir'].'/lengths'; - clearstatcache(); - if (@file_exists($cachename.'.idx')) { - $lengths = @file($cachename.'.idx', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - if ($lengths !== false) { - $idx = array(); - foreach ($lengths as $length) - $idx[] = (int)$length; - return $idx; - } - } - - $dir = @opendir($conf['indexdir']); - if ($dir === false) - return array(); - $lengths[] = array(); - while (($f = readdir($dir)) !== false) { - if (substr($f, 0, 1) == 'i' && substr($f, -4) == '.idx') { - $i = substr($f, 1, -4); - if (is_numeric($i)) - $lengths[] = (int)$i; - } - } - closedir($dir); - sort($lengths); - // save this in a file - $fh = @fopen($cachename.'.tmp', 'w'); - if (!$fh) { - trigger_error("Failed to write index cache", E_USER_ERROR); - return $lengths; - } - @fwrite($fh, implode("\n", $lengths)); - @fclose($fh); - if (isset($conf['fperm'])) - chmod($cachename.'.tmp', $conf['fperm']); - io_rename($cachename.'.tmp', $cachename.'.idx'); - - return $lengths; + return idx_listIndexLengths(); } /** -- GitLab