Commit 0db22db7 by Scott

Add caching to question pages

For logged-out users only.
parent 274bb3c7
...@@ -37,21 +37,39 @@ ...@@ -37,21 +37,39 @@
$questionid=qa_request_part(0); $questionid=qa_request_part(0);
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
$cookieid=qa_cookie_get(); $cookieid=qa_cookie_get();
$pagestate=qa_get_state();
// Get information about this question // Get information about this question
list($question, $childposts, $achildposts, $parentquestion, $closepost, $duplicateposts, $extravalue, $categories, $favorite) = qa_db_select_with_pending( $cacheHandler = Q2A_Storage_CacheManager::getInstance();
qa_db_full_post_selectspec($userid, $questionid), $cacheKey = "page:question:$questionid";
qa_db_full_child_posts_selectspec($userid, $questionid), $useCache = $userid === null && $cacheHandler->isEnabled() && !qa_is_http_post() && empty($pagestate);
qa_db_full_a_child_posts_selectspec($userid, $questionid), $saveCache = false;
qa_db_post_parent_q_selectspec($questionid),
qa_db_post_close_post_selectspec($questionid), if ($useCache) {
qa_db_post_duplicates_selectspec($questionid), $questionData = $cacheHandler->get($cacheKey);
qa_db_post_meta_selectspec($questionid, 'qa_q_extra'), }
qa_db_category_nav_selectspec($questionid, true, true, true),
isset($userid) ? qa_db_is_favorite_selectspec($userid, QA_ENTITY_QUESTION, $questionid) : null if (!isset($questionData)) {
); $questionData = qa_db_select_with_pending(
qa_db_full_post_selectspec($userid, $questionid),
qa_db_full_child_posts_selectspec($userid, $questionid),
qa_db_full_a_child_posts_selectspec($userid, $questionid),
qa_db_post_parent_q_selectspec($questionid),
qa_db_post_close_post_selectspec($questionid),
qa_db_post_duplicates_selectspec($questionid),
qa_db_post_meta_selectspec($questionid, 'qa_q_extra'),
qa_db_category_nav_selectspec($questionid, true, true, true),
isset($userid) ? qa_db_is_favorite_selectspec($userid, QA_ENTITY_QUESTION, $questionid) : null
);
// whether to save the cache (actioned below, after basic checks)
$saveCache = $useCache;
}
list($question, $childposts, $achildposts, $parentquestion, $closepost, $duplicateposts, $extravalue, $categories, $favorite) = $questionData;
if ($question['basetype']!='Q') // don't allow direct viewing of other types of post if ($question['basetype']!='Q') // don't allow direct viewing of other types of post
$question=null; $question=null;
...@@ -135,6 +153,13 @@ ...@@ -135,6 +153,13 @@
} }
// Save question data to cache
if ($saveCache) {
$cacheHandler->set($cacheKey, $questionData, qa_opt('caching_q_time'));
}
// Determine if captchas will be required // Determine if captchas will be required
$captchareason=qa_user_captcha_reason(qa_user_level_for_post($question)); $captchareason=qa_user_captcha_reason(qa_user_level_for_post($question));
...@@ -145,7 +170,6 @@ ...@@ -145,7 +170,6 @@
// This is in a separate file because it's a *lot* of logic, and will slow down ordinary page views // This is in a separate file because it's a *lot* of logic, and will slow down ordinary page views
$pagestart=qa_get_start(); $pagestart=qa_get_start();
$pagestate=qa_get_state();
$showid=qa_get('show'); $showid=qa_get('show');
$pageerror=null; $pageerror=null;
$formtype=null; $formtype=null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment