• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修訂385d77ebb143ce65bdcdd8e964d93adade6222b8 (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())

Change Summary

差異

--- a/lib/file.php
+++ b/lib/file.php
@@ -685,12 +685,41 @@ 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+{
696+ static $cache_enabled = null;
697+
698+ if (!is_null($newvalue)) {
699+ $cache_enabled = $newvalue;
700+ return; // Return nothing on setting newvalue call
701+ }
702+ if (is_null($cache_enabled)) {
703+ return false;
704+ }
705+ return $cache_enabled;
706+}
707+
688708 // Get a page list of this wiki
689709 function get_existpages($dir = DATA_DIR, $ext = '.txt')
690710 {
711+ static $cached_list = null; // Cached wikitext page list
712+ $use_cache = false;
713+
714+ if ($dir === DATA_DIR && $ext === '.txt' && is_pagelist_cache_enabled()) {
715+ // Use pagelist cache for "wiki/*.txt" files
716+ if (!is_null($cached_list)) {
717+ return $cached_list;
718+ }
719+ $use_cache = true;
720+ }
691721 $aryret = array();
692722 $pattern = '/^((?:[0-9A-F]{2})+)' . preg_quote($ext, '/') . '$/';
693-
694723 $dp = @opendir($dir) or die_message($dir . ' is not found or not readable.');
695724 $matches = array();
696725 while (($file = readdir($dp)) !== FALSE) {
@@ -699,7 +728,9 @@ function get_existpages($dir = DATA_DIR, $ext = '.txt')
699728 }
700729 }
701730 closedir($dp);
702-
731+ if ($use_cache) {
732+ $cached_list = $aryret;
733+ }
703734 return $aryret;
704735 }
705736
--- 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-?>