OSDN Git Service

BugTrack/560 Get timestamps of tracker_list pages from cache
authorumorigu <umorigu@gmail.com>
Wed, 28 Feb 2018 15:19:56 +0000 (00:19 +0900)
committerumorigu <umorigu@gmail.com>
Wed, 28 Feb 2018 15:19:56 +0000 (00:19 +0900)
lib/func.php
lib/make_link.php
plugin/tracker.inc.php

index b05584d..4d04fb3 100644 (file)
@@ -2,7 +2,7 @@
 // PukiWiki - Yet another WikiWikiWeb clone.
 // func.php
 // Copyright
-//   2002-2017 PukiWiki Development Team
+//   2002-2018 PukiWiki Development Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
@@ -350,6 +350,27 @@ function get_page_link_a_attrs($page)
        );
 }
 
+/**
+ * Get page link general attributes from filetime
+ * @param $filetime
+ * @return array('data_mtime' => page mtime or null, 'class' => additinal classes)
+ */
+function get_filetime_a_attrs($filetime)
+{
+       global $show_passage;
+       if ($show_passage) {
+               $pagemtime = get_date_atom($filetime + LOCALZONE);
+               return array(
+                       'data_mtime' => $pagemtime,
+                       'class' => get_link_passage_class(),
+               );
+       }
+       return array(
+               'data_mtime' => '',
+               'class' => ''
+       );
+}
+
 // 'Search' main function
 function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
 {
index 3a4f409..d338c52 100644 (file)
@@ -2,12 +2,29 @@
 // PukiWiki - Yet another WikiWikiWeb clone.
 // make_link.php
 // Copyright
-//   2003-2017 PukiWiki Development Team
+//   2003-2018 PukiWiki Development Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
 // Hyperlink-related functions
 
+// To get page exists or filetimes without accessing filesystem
+// Type: array (page => filetime)
+$_cached_page_filetime = null;
+
+// Get filetime from cache
+function fast_get_filetime($page)
+{
+       global $_cached_page_filetime;
+       if (is_null($_cached_page_filetime)) {
+               return get_filetime($page);
+       }
+       if (isset($_cached_page_filetime[$page])) {
+               return $_cached_page_filetime[$page];
+       }
+       return get_filetime($page);
+}
+
 // Hyperlink decoration
 function make_link($string, $page = '')
 {
@@ -763,12 +780,14 @@ function make_pagelink($page, $alias = '', $anchor = '', $refer = '', $isautolin
        $r_page  = pagename_urlencode($page);
        $r_refer = ($refer == '') ? '' : '&amp;refer=' . rawurlencode($refer);
 
-       if (! isset($related[$page]) && $page !== $vars['page'] && is_page($page))
-               $related[$page] = get_filetime($page);
+       $page_filetime = fast_get_filetime($page);
+       $is_page = $page_filetime !== 0;
+       if (! isset($related[$page]) && $page !== $vars['page'] && is_page)
+               $related[$page] = $page_filetime;
 
-       if ($isautolink || is_page($page)) {
+       if ($isautolink || $is_page) {
                // Hyperlink to the page
-               $attrs = get_page_link_a_attrs($page);
+               $attrs = get_filetime_a_attrs($page_filetime);
                // AutoLink marker
                if ($isautolink) {
                        $al_left  = '<!--autolink-->';
index f4e5d50..6087d8e 100644 (file)
@@ -798,7 +798,7 @@ class Tracker_list
        }
        function __construct($page,$refer,&$config,$list,&$cache_holder)
        {
-               global $whatsdeleted;
+               global $whatsdeleted, $_cached_page_filetime;
                $this->page = $page;
                $this->config = &$config;
                $this->list = $list;
@@ -976,6 +976,11 @@ class Tracker_list
                        }
                        $this->link_pages = $new_link_pages;
                        $this->link_update_required = $link_update_required;
+                       $time_map_for_cache = $new_link_map;
+                       foreach ($this->rows as $row) {
+                               $time_map_for_cache[$this->page . '/' . $row['_real']] = $row['_update'];
+                       }
+                       $_cached_page_filetime = $time_map_for_cache;
                }
        }
        function decode_cached_rows($decoded_rows)