Skip to content

Commit

Permalink
Cache: Add additional state variables + single entry mode
Browse files Browse the repository at this point in the history
fetchEntries is heaviliy realient on glboal state variables, and that was missed initially. The last commit c8bbb35 fixed that partially, but did not catch all global state variables. Additionally, this fixed the clean_page mode as used by staticpage by adding the logic and event hook to printEntriesCached
  • Loading branch information
onli committed Apr 19, 2017
1 parent c8bbb35 commit e61d38a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
33 changes: 27 additions & 6 deletions include/functions_entries.inc.php
Expand Up @@ -211,7 +211,7 @@ function &serendipity_fetchEntries($range = null, $full = true, $limit = '', $fe

if ($serendipity['useInternalCache']) {
$cache = serendipity_setupCache();
$key = md5(serialize($initial_args) . $serendipity['GET']['page']);
$key = md5(serialize($initial_args) . $serendipity['short_archives'] . '||' . $serendipity['range'] . '||' . $serendipity['GET']['category'] . '||' . $serendipity['GET']['hide_category'] . '||' . $serendipity['GET']['viewAuthor'] . '||' . $serendipity['GET']['page'] . '||' . $serendipity['fetchLimit'] . '||' . $serendipity['max_fetch_limit'] . '||' . $serendipity['GET']['adminModule'] . '||' . serendipity_checkPermission('adminEntriesMaintainOthers') . '||' .$serendipity['showFutureEntries'] . '||' . $serendipity['archiveSortStable']);

$entries = $cache->get($key, "fetchEntries");
if ($entries !== false) {
Expand Down Expand Up @@ -462,7 +462,8 @@ function &serendipity_fetchEntries($range = null, $full = true, $limit = '', $fe
}

if ($serendipity['useInternalCache']) {
$key = md5(serialize($initial_args) . $serendipity['GET']['page']);
$key = md5(serialize($initial_args) . $serendipity['short_archives'] . '||' . $serendipity['range'] . '||' . $serendipity['GET']['category'] . '||' . $serendipity['GET']['hide_category'] . '||' . $serendipity['GET']['viewAuthor'] . '||' . $serendipity['GET']['page'] . '||' . $serendipity['fetchLimit'] . '||' . $serendipity['max_fetch_limit'] . '||' . $serendipity['GET']['adminModule'] . '||' . serendipity_checkPermission('adminEntriesMaintainOthers') . '||' .$serendipity['showFutureEntries'] . '||' . $serendipity['archiveSortStable']);

$cache->save(serialize($ret), $key, "fetchEntries");
$cache->save($serendipity['fullCountQuery'], $key . '_fullCountQuery', "fetchEntries");
}
Expand Down Expand Up @@ -1057,6 +1058,8 @@ function serendipity_printEntries($entries, $extended = 0, $preview = false, $sm
serendipity_smarty_init(); // if not set, start Smarty templating to avoid member function "method()" on a non-object errors (was draft preview error, now at line 1239)
}

$initial_args = array_values(func_get_args());

if ($use_hooks) {
$addData = array('extended' => $extended, 'preview' => $preview);
serendipity_plugin_api::hook_event('entry_display', $entries, $addData);
Expand Down Expand Up @@ -1276,10 +1279,8 @@ function serendipity_printEntries($entries, $extended = 0, $preview = false, $sm

if ($serendipity['useInternalCache']) {
$cache = serendipity_setupCache();

$args = func_get_args();
$args = array_values($args);
$key = md5(serialize($args));
$key = md5(serialize($initial_args));

$cache->save(serialize($dategroup), $key, "printEntries");
}

Expand Down Expand Up @@ -1307,6 +1308,26 @@ function serendipity_printEntriesCached($entries, $extended = 0, $preview = fals
$key = md5(serialize($args));

if (($dategroup = $cache->get($key, "printEntries")) !== false) {

if ($use_hooks) {
$addData = array('extended' => $extended, 'preview' => $preview);
serendipity_plugin_api::hook_event('entry_display', $entries, $addData);

if (isset($entries['clean_page']) && $entries['clean_page'] === true) {
if ($serendipity['view'] == '404') {
$serendipity['view'] = 'plugin';
}

$serendipity['smarty']->assign(array(
'plugin_clean_page' => true,
'view' => $serendipity['view'])
);
serendipity_smarty_fetch($smarty_block, 'entries.tpl', true);
return; // no display of this item
}
}


$dategroup = unserialize($dategroup);
$serendipity['smarty']->assign('entries', $dategroup);

Expand Down
6 changes: 4 additions & 2 deletions include/genpage.inc.php
Expand Up @@ -48,8 +48,10 @@
serendipity_header('HTTP/1.0 404 Not found');
serendipity_header('Status: 404 Not found');
}

serendipity_printEntries($entry, 1);

if (! serendipity_printEntriesCached($entry, 1)) {
serendipity_printEntries($entry, 1);
}
} else {
serendipity_printEntries(serendipity_fetchEntries($serendipity['range'], true, $serendipity['fetchLimit']));
}
Expand Down

0 comments on commit e61d38a

Please sign in to comment.