- 追加された行はこの色です。
- 削除された行はこの色です。
**概要 [#jda8d90a]
ls2プラグインは、呼び出されるたびにget_existpages()を呼び出すので、
全体で数万ページあるようなサイトでは、1ページ内で何度も#ls2を書くと
リニアに遅くなります。
全体で数万ページあるようなサイトでは、ページ内に何度も#ls2を書くと
無視できないほど遅くなります。
get_existpages()の結果をキャッシュして、複数回呼ばれたときの処理を高速化します。
**内容 [#m161712e]
$ diff -u ls2.inc.php.original ls2.inc.php
--- ls2.inc.php.original 2004-12-05 20:37:37.000000000 +0900
+++ ls2.inc.php 2011-04-01 00:55:33.856430534 +0900
@@ -29,6 +29,9 @@
// 見出しレベルを調整する(デフォルト値)
define('PLUGIN_LS2_LIST_COMPACT', FALSE);
+// Cache of get_existpages() result
+$g_cached_plugin_ls2_existpages = null;
+
function plugin_ls2_action()
{
global $vars, $_ls2_msg_title;
@@ -86,14 +89,18 @@
+++ ls2.inc.php 2011-04-01 01:52:35.372269811 +0900
@@ -86,14 +86,18 @@
function plugin_ls2_show_lists($prefix, & $params)
{
global $_ls2_err_nopages;
+ global $g_cached_plugin_ls2_existpages;
+ static $s_cached_existpages = null;
$pages = array();
+ if ($g_cached_plugin_ls2_existpages === null) {
+ $g_cached_plugin_ls2_existpages = get_existpages();
+ if ($s_cached_existpages === null) {
+ $s_cached_existpages = get_existpages();
+ }
if ($prefix != '') {
- foreach (get_existpages() as $_page)
+ foreach ($g_cached_plugin_ls2_existpages as $_page)
+ foreach ($s_cached_existpages as $_page)
if (strpos($_page, $prefix) === 0)
$pages[] = $_page;
} else {
- $pages = get_existpages();
+ $pages = $g_cached_plugin_ls2_existpages;
+ $pages = $s_cached_existpages;
}
natcasesort($pages);
**効果 [#ydecabb2]
- 全体ページ数2万のあるサイト、#ls2(キーワード) が 45あったあるページのHTML convert time:
-- 改善前: 35秒 → 改善後 2秒
**コメント [#oc970c7a]
- 遅かったので対策しました。 -- [[umorigu]] &new{2011-04-21 (木) 00:33:38};
- get_existpages()側でキャッシュすればls2に限らず高速化されるとか... -- &new{2011-04-21 (木) 00:31:17};
- されます。get_existpages()の変更は影響範囲を読めなかったので今回はls2だけにしました。[[ここ>http://www.revulo.com/PukiWiki/Cache/PagenameCache.html]]ではget_existpages()内でキャッシュしているようです -- [[umorigu]] &new{2011-04-21 (木) 00:35:57};
- 「影響範囲」というのは「get_existpages()→ページ追加・削除→get_existpages()というケースがあるかも?」という懸念です -- [[umorigu]] &new{2011-04-21 (木) 00:57:04};
#comment