**概要 [#jda8d90a]

ls2プラグインは、呼び出されるたびにget_existpages()を呼び出すので、
全体で数万ページあるようなサイトでは、1ページ内で何度も#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 @@
  function plugin_ls2_show_lists($prefix, & $params)
  {
         global $_ls2_err_nopages;
 +       global $g_cached_plugin_ls2_existpages;
  
         $pages = array();
 +       if ($g_cached_plugin_ls2_existpages === null) {
 +               $g_cached_plugin_ls2_existpages = get_existpages();
 +       }
         if ($prefix != '') {
 -               foreach (get_existpages() as $_page)
 +               foreach ($g_cached_plugin_ls2_existpages  as $_page)
                         if (strpos($_page, $prefix) === 0)
                                 $pages[] = $_page;
         } else {
 -               $pages = get_existpages();
 +               $pages = $g_cached_plugin_ls2_existpages;
         }
  
         natcasesort($pages);



**コメント [#oc970c7a]

#comment


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Site admin: PukiWiki Development Team

PukiWiki 1.5.4+ © 2001-2022 PukiWiki Development Team. Powered by PHP 8.2.12. HTML convert time: 0.007 sec.

SourceForge