Revision | 51239db40c60ac247bca93349bb918146a83494f (tree) |
---|---|
Time | 2018-03-14 22:01:26 |
Author | umorigu <umorigu@gmai...> |
Commiter | umorigu |
BugTrack/2401 bugtrack_list: Improve cache management
Use converted HTML text when cache/recent.dat is unchanged.
@@ -288,6 +288,7 @@ function plugin_bugtrack_get_page_list($page, $needs_filetime) { | ||
288 | 288 | function plugin_bugtrack_list_convert() |
289 | 289 | { |
290 | 290 | global $vars, $_plugin_bugtrack, $_title_cannotread; |
291 | + global $whatsdeleted; | |
291 | 292 | $cache_format_version = 1; |
292 | 293 | $cache_expire_time = 60 * 60 * 24; |
293 | 294 | $cache_refresh_time_prev; |
@@ -305,6 +306,22 @@ function plugin_bugtrack_list_convert() | ||
305 | 306 | $body = str_replace('$1', htmlsc($page), $_title_cannotread); |
306 | 307 | return $body; |
307 | 308 | } |
309 | + if ($cache_enabled) { | |
310 | + $cache_filepath = CACHE_DIR . encode($page) . '.bugtrack'; | |
311 | + $json_cached = pkwk_file_get_contents($cache_filepath); | |
312 | + $wrapdata = json_decode($json_cached); | |
313 | + if (is_object($wrapdata) && $wrapdata) { | |
314 | + $recent_deleted_filetime = get_filetime($whatsdeleted); | |
315 | + $recent_dat_filemtime = filemtime(CACHE_DIR . PKWK_MAXSHOW_CACHE); | |
316 | + if ($recent_deleted_filetime === $wrapdata->recent_deleted_filetime && | |
317 | + $recent_dat_filemtime === $wrapdata->recent_dat_filemtime && | |
318 | + $recent_dat_filemtime !== false && | |
319 | + $recent_deleted_filetime !== 0) { | |
320 | + return $wrapdata->html; | |
321 | + } | |
322 | + } | |
323 | + } | |
324 | + $cache_data = null; | |
308 | 325 | $data = array(); |
309 | 326 | $page_list = plugin_bugtrack_get_page_list($page, true); |
310 | 327 | usort($page_list, '_plugin_bugtrack_list_paganame_compare'); |
@@ -400,9 +417,7 @@ EOD; | ||
400 | 417 | } else { |
401 | 418 | $refreshed_at = time(); |
402 | 419 | } |
403 | - $json = array('refreshed_at'=>$refreshed_at, 'pages'=>$data, 'version'=>$cache_format_version); | |
404 | - $cache_body = json_encode($json, JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES); | |
405 | - file_put_contents($cache_filepath, $cache_body, LOCK_EX); | |
420 | + $cache_data = array('refreshed_at'=>$refreshed_at, 'pages'=>$data, 'version'=>$cache_format_version); | |
406 | 421 | } |
407 | 422 | } |
408 | 423 | $table = array(); |
@@ -419,9 +434,17 @@ EOD; | ||
419 | 434 | ksort($table[$i], SORT_NUMERIC); |
420 | 435 | $table_html .= join('', $table[$i]); |
421 | 436 | } |
422 | - return '<table border="1" width="100%">' . "\n" . | |
437 | + $result_html = '<table border="1" width="100%">' . "\n" . | |
423 | 438 | $table_html . "\n" . |
424 | 439 | '</table>'; |
440 | + if ($cache_enabled) { | |
441 | + $cache_data['recent_deleted_filetime'] = get_filetime($whatsdeleted); | |
442 | + $cache_data['recent_dat_filemtime'] = filemtime(CACHE_DIR . PKWK_MAXSHOW_CACHE); | |
443 | + $cache_data['html'] = $result_html; | |
444 | + $cache_body = json_encode($cache_data, JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES); | |
445 | + file_put_contents($cache_filepath, $cache_body, LOCK_EX); | |
446 | + } | |
447 | + return $result_html; | |
425 | 448 | } |
426 | 449 | |
427 | 450 | // Get one set of data from a page (or a page moved to $page) |