PDA

View Full Version : Incorrect calculation of statistics


denverwork
09-09-2021, 09:00 AM
Faced with the problem that the data for statistics are calculated incorrectly by cron.
For example, new threads.
core/includes/cron/stats.php:

...
// new threads
$newtopics = vB::getDbAssertor()->getRow('vBForum:getStarterStats', array('timestamp' => $timestamp));
...

core/packages/vbforum/db/mysql/querydefs.php:

...
'getStarterStats' => array(vB_dB_Query::QUERYTYPE_KEY => vB_dB_Query::QUERY_SELECT,
'query_string' => "
SELECT COUNT(*) AS count
FROM {TABLE_PREFIX}node
WHERE (starter=nodeid) AND publishdate > {timestamp}
"),
...

This data is calculated by the script and written to the table stats, which is run by cron.
When calculating the data in this case, not only new posts are included, but also private messages.

But if you start manually recalculating statistics in the admin panel, then the logic is as follows,
core/admincp/misc.php:

// new threads
$newthreads = $vbulletin->db->query_first('SELECT COUNT(nodeid) AS total FROM ' . TABLE_PREFIX . 'node AS node INNER JOIN ' . TABLE_PREFIX . 'closure AS cl ON cl.parent = ' . $forumChannel . ' WHERE node.nodeid = node.starter AND cl.child = node.nodeid AND node.publishdate >= ' . $timestamp . ' AND node.publishdate < ' . ($timestamp + 86400));



Why such a difference can be in the code? And how to fix it correctly so as not to make changes to the core?