Fixed Daily Statistics: "user_activity" date is off by one day

Steffen

Well-known member
Affected version
2.0.6
Have a look at the contents of your xf_stats_daily table sorted by stats_date DESC. Notice that there is a "user_activity" entry whose date is one day (86400 seconds) ahead of all the other entries.

I think the reason is that XF\Stats\User::getData computes a wrong date for "user_activity" entries. It stores yesterday's active users with a date of today.

Have a look at the "Users active" statistics in the Admin CP: A value is available for today although XenForo cannot possibly know how many active users we'll have today. :D What's shown is yesterday's value (with a wrong date).

XF\Stats\User::getData uses the current time but I think it should probably use the requested range.

Maybe this is the correct fix:
Diff:
diff --git a/src/XF/Stats/User.php b/src/XF/Stats/User.php
index 123dea44e..91117df9d 100644
--- a/src/XF/Stats/User.php
+++ b/src/XF/Stats/User.php
@@ -23,7 +23,7 @@ class User extends AbstractHandler

         // this will only ever fetch the past 24 hours
         $usersActive = $db->fetchPairs('
-            SELECT ' . (\XF::$time - \XF::$time % 86400) . ',
+            SELECT ' . ($start - $start % 86400) . ',
                 COUNT(*)
             FROM xf_user
             WHERE last_activity > ?
 
Last edited:
Top Bottom