Commit 9b0c46ae by Simon Champion

Strip redundant code from main recalc class.

parent bbc66e0f
......@@ -105,532 +105,6 @@ class Q2A_Recalc_RecalcMain
return $continue && !$this->state->allDone();
}
private function DoReindexContent()
{
$this->state->transition('doreindexcontent_pagereindex');
}
private function DoReindexContent_PageReindex()
{
$pages = qa_db_pages_get_for_reindexing($this->state->next, 10);
if (!count($pages)) {
$this->state->transition('doreindexcontent_postcount');
return false;
}
require_once QA_INCLUDE_DIR . 'app/format.php';
$lastpageid = max(array_keys($pages));
foreach ($pages as $pageid => $page) {
if (!($page['flags'] & QA_PAGE_FLAGS_EXTERNAL)) {
$searchmodules_u = qa_load_modules_with('search', 'unindex_page');
foreach ($searchmodules_u as $searchmodule) {
$searchmodule->unindex_page($pageid);
}
$searchmodules_i = qa_load_modules_with('search', 'index_page');
if (count($searchmodules_i)) {
$indextext = qa_viewer_text($page['content'], 'html');
foreach ($searchmodules_i as $searchmodule) {
$searchmodule->index_page($pageid, $page['tags'], $page['heading'], $page['content'], 'html', $indextext);
}
}
}
}
$this->state->next = 1 + $lastpageid;
$this->state->done += count($pages);
return true;
}
private function DoReindexContent_PostCount()
{
qa_db_qcount_update();
qa_db_acount_update();
qa_db_ccount_update();
$this->state->transition('doreindexcontent_postreindex');
return false;
}
private function DoReindexContent_PostReindex()
{
$posts = qa_db_posts_get_for_reindexing($this->state->next, 10);
if (!count($posts)) {
qa_db_truncate_indexes($this->state->next);
$this->state->transition('doreindexposts_wordcount');
return false;
}
require_once QA_INCLUDE_DIR . 'app/format.php';
$lastpostid = max(array_keys($posts));
qa_db_prepare_for_reindexing($this->state->next, $lastpostid);
qa_suspend_update_counts();
foreach ($posts as $postid => $post) {
qa_post_unindex($postid);
qa_post_index($postid, $post['type'], $post['questionid'], $post['parentid'], $post['title'], $post['content'],
$post['format'], qa_viewer_text($post['content'], $post['format']), $post['tags'], $post['categoryid']);
}
$this->state->next = 1 + $lastpostid;
$this->state->done += count($posts);
return true;
}
private function DoReindexPosts_WordCount()
{
$wordids = qa_db_words_prepare_for_recounting($this->state->next, 1000);
if (!count($wordids)) {
qa_db_tagcount_update(); // this is quick so just do it here
$this->state->transition('doreindexposts_complete');
return false;
}
$lastwordid = max($wordids);
qa_db_words_recount($this->state->next, $lastwordid);
$this->state->next = 1 + $lastwordid;
$this->state->done += count($wordids);
return true;
}
private function DoRecountPosts()
{
$this->state->transition('dorecountposts_postcount');
return false;
}
private function DoRecountPosts_PostCount()
{
qa_db_qcount_update();
qa_db_acount_update();
qa_db_ccount_update();
qa_db_unaqcount_update();
qa_db_unselqcount_update();
$this->state->transition('dorecountposts_votecount');
return false;
}
private function DoRecountPosts_VoteCount()
{
$postids = qa_db_posts_get_for_recounting($this->state->next, 1000);
if (!count($postids)) {
$this->state->transition('dorecountposts_acount');
return false;
}
$lastpostid = max($postids);
qa_db_posts_votes_recount($this->state->next, $lastpostid);
$this->state->next = 1 + $lastpostid;
$this->state->done += count($postids);
return true;
}
private function DoRecountPosts_Acount()
{
$postids = qa_db_posts_get_for_recounting($this->state->next, 1000);
if (count($postids)) {
qa_db_unupaqcount_update();
$this->state->transition('dorecountposts_complete');
return false;
}
$lastpostid = max($postids);
qa_db_posts_answers_recount($this->state->next, $lastpostid);
$this->state->next = 1 + $lastpostid;
$this->state->done += count($postids);
return true;
}
private function DoRecalcPoints()
{
$this->state->transition('dorecalcpoints_usercount');
return false;
}
private function DoRecalcPoints_UserCount()
{
qa_db_userpointscount_update(); // for progress update - not necessarily accurate
qa_db_uapprovecount_update(); // needs to be somewhere and this is the most appropriate place
$this->state->transition('dorecalcpoints_recalc');
return false;
}
private function DoRecalcPoints_Recalc()
{
$default_recalccount = 10;
$userids = qa_db_users_get_for_recalc_points($this->state->next, $default_recalccount + 1); // get one extra so we know where to start from next
$gotcount = count($userids);
$recalccount = min($default_recalccount, $gotcount); // can't recalc more than we got
if ($recalccount > 0) {
$lastuserid = $userids[$recalccount - 1];
qa_db_users_recalc_points($this->state->next, $lastuserid);
$this->state->done += $recalccount;
} else {
$lastuserid = $this->state->next; // for truncation
}
if ($gotcount > $recalccount) { // more left to do
$this->state->next = $userids[$recalccount]; // start next round at first one not recalculated
return true;
} else {
qa_db_truncate_userpoints($lastuserid);
qa_db_userpointscount_update(); // quick so just do it here
$this->state->transition('dorecalcpoints_complete');
return false;
}
}
private function DoRefillEvents()
{
$this->state->transition('dorefillevents_qcount');
return false;
}
private function DoRefillEvents_Qcount()
{
qa_db_qcount_update();
$this->state->transition('dorefillevents_refill');
return false;
}
private function DoRefillEvents_Refill()
{
$questionids = qa_db_qs_get_for_event_refilling($this->state->next, 1);
if (!count($questionids)) {
$this->state->transition('dorefillevents_complete');
return false;
}
require_once QA_INCLUDE_DIR . 'app/events.php';
require_once QA_INCLUDE_DIR . 'app/updates.php';
require_once QA_INCLUDE_DIR . 'util/sort.php';
$lastquestionid = max($questionids);
foreach ($questionids as $questionid) {
// Retrieve all posts relating to this question
list($question, $childposts, $achildposts) = qa_db_select_with_pending(
qa_db_full_post_selectspec(null, $questionid),
qa_db_full_child_posts_selectspec(null, $questionid),
qa_db_full_a_child_posts_selectspec(null, $questionid)
);
// Merge all posts while preserving keys as postids
$posts = array($questionid => $question);
foreach ($childposts as $postid => $post) {
$posts[$postid] = $post;
}
foreach ($achildposts as $postid => $post) {
$posts[$postid] = $post;
}
// Creation and editing of each post
foreach ($posts as $postid => $post) {
$followonq = ($post['basetype'] == 'Q') && ($postid != $questionid);
if ($followonq) {
$updatetype = QA_UPDATE_FOLLOWS;
} elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'Q') {
$updatetype = QA_UPDATE_C_FOR_Q;
} elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'A') {
$updatetype = QA_UPDATE_C_FOR_A;
} else {
$updatetype = null;
}
qa_create_event_for_q_user($questionid, $postid, $updatetype, $post['userid'], @$posts[$post['parentid']]['userid'], $post['created']);
if (isset($post['updated']) && !$followonq) {
qa_create_event_for_q_user($questionid, $postid, $post['updatetype'], $post['lastuserid'], $post['userid'], $post['updated']);
}
}
// Tags and categories of question
qa_create_event_for_tags($question['tags'], $questionid, null, $question['userid'], $question['created']);
qa_create_event_for_category($question['categoryid'], $questionid, null, $question['userid'], $question['created']);
// Collect comment threads
$parentidcomments = array();
foreach ($posts as $postid => $post) {
if ($post['basetype'] == 'C') {
$parentidcomments[$post['parentid']][$postid] = $post;
}
}
// For each comment thread, notify all previous comment authors of each comment in the thread (could get slow)
foreach ($parentidcomments as $parentid => $comments) {
$keyuserids = array();
qa_sort_by($comments, 'created');
foreach ($comments as $comment) {
foreach ($keyuserids as $keyuserid => $dummy) {
if ($keyuserid != $comment['userid'] && $keyuserid != @$posts[$parentid]['userid']) {
qa_db_event_create_not_entity($keyuserid, $questionid, $comment['postid'], QA_UPDATE_FOLLOWS, $comment['userid'], $comment['created']);
}
}
if (isset($comment['userid'])) {
$keyuserids[$comment['userid']] = true;
}
}
}
}
$this->state->next = 1 + $lastquestionid;
$this->state->done += count($questionids);
return true;
}
private function DoRecalcCategories()
{
$this->state->transition('dorecalccategories_postcount');
return false;
}
private function DoRecalcCategories_PostCount()
{
qa_db_acount_update();
qa_db_ccount_update();
$this->state->transition('dorecalccategories_postupdate');
return false;
}
private function DoRecalcCategories_PostUpdate()
{
$postids = qa_db_posts_get_for_recategorizing($this->state->next, 100);
if (!count($postids)) {
$this->state->transition('dorecalccategories_recount');
return false;
}
$lastpostid = max($postids);
qa_db_posts_recalc_categoryid($this->state->next, $lastpostid);
qa_db_posts_calc_category_path($this->state->next, $lastpostid);
$this->state->next = 1 + $lastpostid;
$this->state->done += count($postids);
return true;
}
private function DoRecalcCategories_Recount()
{
$categoryids = qa_db_categories_get_for_recalcs($this->state->next, 10);
if (!count($categoryids)) {
$this->state->transition('dorecalccategories_backpaths');
return false;
}
$lastcategoryid = max($categoryids);
foreach ($categoryids as $categoryid) {
qa_db_ifcategory_qcount_update($categoryid);
}
$this->state->next = 1 + $lastcategoryid;
$this->state->done += count($categoryids);
return true;
}
private function DoRecalcCategories_BackPaths()
{
$categoryids = qa_db_categories_get_for_recalcs($this->state->next, 10);
if (!count($categoryids)) {
$this->state->transition('dorecalccategories_complete');
return false;
}
$lastcategoryid = max($categoryids);
qa_db_categories_recalc_backpaths($this->state->next, $lastcategoryid);
$this->state->next = 1 + $lastcategoryid;
$this->state->done += count($categoryids);
return true;
}
private function DoDeleteHidden()
{
$this->state->transition('dodeletehidden_comments');
return false;
}
private function DoDeleteHidden_Comments()
{
$posts = qa_db_posts_get_for_deleting('C', $this->state->next, 1);
if (!count($posts)) {
$this->state->transition('dodeletehidden_answers');
return false;
}
require_once QA_INCLUDE_DIR . 'app/posts.php';
$postid = $posts[0];
qa_post_delete($postid);
$this->state->next = 1 + $postid;
$this->state->done++;
return true;
}
private function DoDeleteHidden_Answers()
{
$posts = qa_db_posts_get_for_deleting('A', $this->state->next, 1);
if (!count($posts)) {
$this->state->transition('dodeletehidden_questions');
return false;
}
require_once QA_INCLUDE_DIR . 'app/posts.php';
$postid = $posts[0];
qa_post_delete($postid);
$this->state->next = 1 + $postid;
$this->state->done++;
return true;
}
private function Dodeletehidden_questions()
{
$posts = qa_db_posts_get_for_deleting('Q', $this->state->next, 1);
if (!count($posts)) {
$this->state->transition('dodeletehidden_complete');
return false;
}
require_once QA_INCLUDE_DIR . 'app/posts.php';
$postid = $posts[0];
qa_post_delete($postid);
$this->state->next = 1 + $postid;
$this->state->done++;
return true;
}
private function DoBlobsToDisk()
{
$this->state->transition('doblobstodisk_move');
return false;
}
private function DoBlobsToDisk_Move()
{
$blob = qa_db_get_next_blob_in_db($this->state->next);
if (!isset($blob)) {
$this->state->transition('doblobstodisk_complete');
return false;
}
require_once QA_INCLUDE_DIR . 'app/blobs.php';
require_once QA_INCLUDE_DIR . 'db/blobs.php';
if (qa_write_blob_file($blob['blobid'], $blob['content'], $blob['format'])) {
qa_db_blob_set_content($blob['blobid'], null);
}
$this->state->next = 1 + $blob['blobid'];
$this->state->done++;
return true;
}
private function DoBlobsToDB()
{
$this->state->transition('doblobstodb_move');
return false;
}
private function DoBlobsToDB_Move()
{
$blob = qa_db_get_next_blob_on_disk($this->state->next);
if (!isset($blob)) {
$this->state->transition('doblobstodb_complete');
return false;
}
require_once QA_INCLUDE_DIR . 'app/blobs.php';
require_once QA_INCLUDE_DIR . 'db/blobs.php';
$content = qa_read_blob_file($blob['blobid'], $blob['format']);
qa_db_blob_set_content($blob['blobid'], $content);
qa_delete_blob_file($blob['blobid'], $blob['format']);
$this->state->next = 1 + $blob['blobid'];
$this->state->done++;
return true;
}
private function DoCacheTrim()
{
$this->state->transition('docachetrim_process');
return false;
}
private function DoCacheClear()
{
$this->state->transition('docacheclear_process');
return false;
}
private function DoCacheTrim_Process()
{
return $this->Docacheclear_process();
}
private function DoCacheClear_Process()
{
$cacheDriver = Q2A_Storage_CacheFactory::getCacheDriver();
$cacheStats = $cacheDriver->getStats();
$limit = min($cacheStats['files'], 20);
if (!($cacheStats['files'] > 0 && $this->state->next <= $this->state->length)) {
$this->state->transition('docacheclear_complete');
return false;
}
$deleted = $cacheDriver->clear($limit, $this->state->next, ($this->state->operation === 'docachetrim_process'));
$this->state->done += $deleted;
$this->state->next += $limit - $deleted; // skip files that weren't deleted on next iteration
return true;
}
/**
* Return the translated language ID string replacing the progress and total in it.
* @access private
......
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