Revision | ac84fd433d64521d40bb7ff4ceeb54da300219b4 (tree) |
---|---|
Zeit | 2017-10-23 03:21:45 |
Autor | umorigu <umorigu@gmai...> |
Commiter | umorigu |
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())
@@ -685,12 +685,40 @@ function get_existfiles($dir = DATA_DIR, $ext = '.txt') | ||
685 | 685 | return $aryret; |
686 | 686 | } |
687 | 687 | |
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 | + | |
688 | 707 | // Get a page list of this wiki |
689 | 708 | function get_existpages($dir = DATA_DIR, $ext = '.txt') |
690 | 709 | { |
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 | + } | |
691 | 720 | $aryret = array(); |
692 | 721 | $pattern = '/^((?:[0-9A-F]{2})+)' . preg_quote($ext, '/') . '$/'; |
693 | - | |
694 | 722 | $dp = @opendir($dir) or die_message($dir . ' is not found or not readable.'); |
695 | 723 | $matches = array(); |
696 | 724 | while (($file = readdir($dp)) !== FALSE) { |
@@ -699,7 +727,9 @@ function get_existpages($dir = DATA_DIR, $ext = '.txt') | ||
699 | 727 | } |
700 | 728 | } |
701 | 729 | closedir($dp); |
702 | - | |
730 | + if ($use_cache) { | |
731 | + $cached_list = $aryret; | |
732 | + } | |
703 | 733 | return $aryret; |
704 | 734 | } |
705 | 735 |
@@ -1,6 +1,8 @@ | ||
1 | 1 | <?php |
2 | 2 | // 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 | |
4 | 6 | // |
5 | 7 | // Read plugin: Show a page and InterWiki |
6 | 8 |
@@ -9,22 +11,22 @@ function plugin_read_action() | ||
9 | 11 | global $vars, $_title_invalidwn, $_msg_invalidiwn; |
10 | 12 | |
11 | 13 | $page = isset($vars['page']) ? $vars['page'] : ''; |
12 | - | |
13 | 14 | if (is_page($page)) { |
14 | - // ページを表示 | |
15 | + // Show this page | |
15 | 16 | check_readable($page, true, true); |
16 | 17 | header_lastmod($page); |
18 | + is_pagelist_cache_enabled(true); // Enable get_existpage() cache | |
17 | 19 | return array('msg'=>'', 'body'=>''); |
18 | 20 | |
19 | 21 | } else if (! PKWK_SAFE_MODE && is_interwiki($page)) { |
20 | - return do_plugin_action('interwiki'); // InterWikiNameを処理 | |
22 | + return do_plugin_action('interwiki'); // Process InterWikiName | |
21 | 23 | |
22 | 24 | } else if (is_pagename($page)) { |
23 | 25 | $vars['cmd'] = 'edit'; |
24 | - return do_plugin_action('edit'); // 存在しないので、編集フォームを表示 | |
26 | + return do_plugin_action('edit'); // Page not found, then show edit form | |
25 | 27 | |
26 | 28 | } else { |
27 | - // 無効なページ名 | |
29 | + // Invalid page name | |
28 | 30 | return array( |
29 | 31 | 'msg'=>$_title_invalidwn, |
30 | 32 | 'body'=>str_replace('$1', htmlsc($page), |
@@ -32,4 +34,3 @@ function plugin_read_action() | ||
32 | 34 | ); |
33 | 35 | } |
34 | 36 | } |
35 | -?> |