XF 2.2 user list oder by last_activity is caching, how to force update it?

Earl

Well-known member
I have this line in my repository
PHP:
$recent_active_user = $this->finder('XF:User')->where('user_id', $userIds)->>order(
 'last_activity',
 'DESC',
)->fetchOne();

$userIds has few ID numbers, and I want to find the recent active user from this few users, but I don't get the accurate update when I order it by the last_activity field.
I tested this by putting an old user into this $userIds array, and logged into that ID and executed the code.
but that $recent_active_user value did not set to that user.

Is there a way to force update this list? Or what's the recommended way to accurately get the most recent active user from a users array ?
 
Last edited:
Okay, I found these two lines from the hourly cleanUp job:

PHP:
/** @var \XF\Repository\SessionActivity $activityRepo */
$activityRepo = $this->repository('XF:SessionActivity');
$activityRepo->updateUserLastActivityFromSession();

I believe adding these two lines to my add-on code would fix it, but I need to know if it's safe to force update this instead of waiting for the hourly cleanup job to finish.

ps: my add-on code is not in a public place. It is only executed in API calls, and it doesn't happen regularly but it needs the most updated results.
 
Back
Top Bottom