Commit MetaInfo

修订版ac84fd433d64521d40bb7ff4ceeb54da300219b4 (tree)
时间2017-10-23 03:21:45
作者umorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2438 Fasten get_existpages() for ls2 plugin

Cache get_existpages() result (page list) of wiki/*.txt
Enable cache after calling read plugin (plugin_read_action())

更改概述

差异

--- a/lib/file.php
+++ b/lib/file.php
@@ -685,12 +685,40 @@ function get_existfiles($dir = DATA_DIR, $ext = '.txt')
685685 return $aryret;
686686 }
687687
688+/**
689+ * Get/Set pagelist cache enabled for get_existpages()
690+ *
691+ * @param $newvalue Set true when the system can cache the page list
692+ * @return true if can use page list cache
693+ */
694+function is_pagelist_cache_enabled($newvalue = null) {
695+ static $cache_enabled = null;
696+
697+ if (!is_null($newvalue)) {
698+ $cache_enabled = $newvalue;
699+ return; // Return nothing on setting newvalue call
700+ }
701+ if (is_null($cache_enabled)) {
702+ return false;
703+ }
704+ return $cache_enabled;
705+}
706+
688707 // Get a page list of this wiki
689708 function get_existpages($dir = DATA_DIR, $ext = '.txt')
690709 {
710+ static $cached_list = null; // Cached wikitext page list
711+ $use_cache = false;
712+
713+ if ($dir === DATA_DIR && $ext === '.txt' && is_pagelist_cache_enabled()) {
714+ // Use pagelist cache for "wiki/*.txt" files
715+ if (!is_null($cached_list)) {
716+ return $cached_list;
717+ }
718+ $use_cache = true;
719+ }
691720 $aryret = array();
692721 $pattern = '/^((?:[0-9A-F]{2})+)' . preg_quote($ext, '/') . '$/';
693-
694722 $dp = @opendir($dir) or die_message($dir . ' is not found or not readable.');
695723 $matches = array();
696724 while (($file = readdir($dp)) !== FALSE) {
@@ -699,7 +727,9 @@ function get_existpages($dir = DATA_DIR, $ext = '.txt')
699727 }
700728 }
701729 closedir($dp);
702-
730+ if ($use_cache) {
731+ $cached_list = $aryret;
732+ }
703733 return $aryret;
704734 }
705735
--- a/plugin/read.inc.php
+++ b/plugin/read.inc.php
@@ -1,6 +1,8 @@
11 <?php
22 // PukiWiki - Yet another WikiWikiWeb clone.
3-// $Id: read.inc.php,v 1.9 2011/01/25 15:01:01 henoheno Exp $
3+// read.inc.php
4+// Copyright 2003-2017 PukiWiki Development Team
5+// License: GPL v2 or (at your option) any later version
46 //
57 // Read plugin: Show a page and InterWiki
68
@@ -9,22 +11,22 @@ function plugin_read_action()
911 global $vars, $_title_invalidwn, $_msg_invalidiwn;
1012
1113 $page = isset($vars['page']) ? $vars['page'] : '';
12-
1314 if (is_page($page)) {
14- // ページを表示
15+ // Show this page
1516 check_readable($page, true, true);
1617 header_lastmod($page);
18+ is_pagelist_cache_enabled(true); // Enable get_existpage() cache
1719 return array('msg'=>'', 'body'=>'');
1820
1921 } else if (! PKWK_SAFE_MODE && is_interwiki($page)) {
20- return do_plugin_action('interwiki'); // InterWikiNameを処理
22+ return do_plugin_action('interwiki'); // Process InterWikiName
2123
2224 } else if (is_pagename($page)) {
2325 $vars['cmd'] = 'edit';
24- return do_plugin_action('edit'); // 存在しないので、編集フォームを表示
26+ return do_plugin_action('edit'); // Page not found, then show edit form
2527
2628 } else {
27- // 無効なページ名
29+ // Invalid page name
2830 return array(
2931 'msg'=>$_title_invalidwn,
3032 'body'=>str_replace('$1', htmlsc($page),
@@ -32,4 +34,3 @@ function plugin_read_action()
3234 );
3335 }
3436 }
35-?>
Show on old repository browser