Skip to content

[$40] Comment count is wrong in the roundtables #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sdgun opened this issue Feb 11, 2021 · 7 comments
Closed

[$40] Comment count is wrong in the roundtables #386

sdgun opened this issue Feb 11, 2021 · 7 comments

Comments

@sdgun
Copy link
Collaborator

sdgun commented Feb 11, 2021

Steps
Go to https://vanilla.topcoder-dev.com/categories/general
The comment count in General Discussion is 3.8k
Click General Discussion and check the comments in the discussions there
The discussion 'Perf Test only has 4.2k comments

image

image

@sdgun sdgun added bug Something isn't working P2 Roundtables labels Feb 11, 2021
@jmgasper jmgasper changed the title Comment count is wrong in the roundtables [$40] Comment count is wrong in the roundtables Feb 11, 2021
@sdgun sdgun added the Dev env label Feb 15, 2021
@jmgasper
Copy link
Collaborator

Challenge https://www.topcoder.com/challenges/f2471587-f507-49d2-92cc-847a3a5cd15c has been created for this ticket.

This is an automated message for ghostar via Topcoder X

@jmgasper
Copy link
Collaborator

Challenge https://www.topcoder.com/challenges/f2471587-f507-49d2-92cc-847a3a5cd15c has been assigned to obog.

This is an automated message for ghostar via Topcoder X

@atelomycterus
Copy link
Collaborator

@jmgasper I'm going to have a look at after #400 (#381). After adding a comment aggregate count column (CountComments) is recalculated in two ways.

Source: vanilla/applications/vanilla/models/class.commentmodel.php

  1. /** Threshold. */
    const COMMENT_THRESHOLD_SMALL = 1000;
/** Threshold. */
const COMMENT_THRESHOLD_LARGE = 50000;

/** Trigger to recalculate counter. */
const COUNT_RECALC_MOD = 50;
 // We may or may not perform a MySQL sum to update the count. Verify using threshold constants.
        $countComments = val('CountComments', $category, 0);
        $countBelowThreshold = $countComments < CommentModel::COMMENT_THRESHOLD_SMALL;
        $countScheduledUpdate = ($countComments < CommentModel::COMMENT_THRESHOLD_LARGE && $countComments % CommentModel::COUNT_RECALC_MOD == 0);

        if ($countBelowThreshold || $countScheduledUpdate) {
            $countComments = Gdn::sql()->select('CountComments', 'sum', 'CountComments')
                ->from('Discussion')
                ->where('CategoryID', $categoryID)
                ->get()
                ->firstRow()
                ->CountComments;
        } else {
            // No SQL sum means we're going with a regular ole PHP increment.
            $countComments++;
        }

  1. Validate recalculation of a category and its ancestors
   /**
    * Update the latest post info for a category and its ancestors.
    *
    * @param int|array|object $discussion
    * @param int|array|object $comment
    */
   public static function updateModifiedComment($comment) {
       // Should we attempt to fetch a comment?
       if (is_numeric($comment)) {
           $comment = CommentModel::instance()->getID($comment);
       }
       $discussionID = val('DiscussionID', $comment);
       if(!$discussionID) {
           return;
       }
       $discussionModel = new DiscussionModel();
       $discussion = $discussionModel->getID($discussionID);
       $categoryID = val('CategoryID', $discussion);
       // Discussion-related field values.
       $cache = static::modifiedCommentCacheFields($comment);
       $db = static::modifiedCommentDBFields($comment);

       $categories = self::instance()->collection->getAncestors($categoryID, true);
       foreach ($categories as $row) {
           $currentCategoryID = val('CategoryID', $row);
           self::instance()->setField($currentCategoryID, $db);
           CategoryModel::setCache($currentCategoryID, $cache);
       }
   }

@atelomycterus
Copy link
Collaborator

@sdgun Could you validate it after deploying #381? Thanks!

@jmgasper
Copy link
Collaborator

@sdgun - Deploy is done.

@sdgun
Copy link
Collaborator Author

sdgun commented Feb 22, 2021

Verified in Dev, comment count is correct now.

@jmgasper
Copy link
Collaborator

Payment task has been updated: https://www.topcoder.com/challenges/f2471587-f507-49d2-92cc-847a3a5cd15c
Payments Complete
Winner: obog
Copilot: ghostar
Challenge f2471587-f507-49d2-92cc-847a3a5cd15c has been paid and closed.

This is an automated message for ghostar via Topcoder X

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants