1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

last_activity in xf_user

Discussion in 'XenForo Development Discussions' started by Phases, Oct 14, 2010.

  1. Phases

    Phases Active Member

    I have a "Five most recent users" thing going on my homepage, here:


    ...which pulls the most recent five from last_activity in the xf_user table. However, it is as dynamic as I would expect, or it would appear it should be. As in, users will post, but it won't be reflected (yet?).

    If you look at the forums and look at the latest posts, it's not in the order it should be in the top five thing.

    So I thought, well maybe just them clicking around is (and should be) reflected in last activity, and that could explain it except - the order doesn't change. Things stay the same. Same top five in same order.

    However, they DO change after some time.

    So I'm asking I guess, is last_activity run on a cron, and does anyone know what actions will prompt a change in that field?
  2. Kier

    Kier XenForo Developer Staff Member

    Take a look at XenForo_ControllerPublic_Member::actionCard().

    You can see in there that the user is fetched with XenForo_Model_User::FETCH_LAST_ACTIVITY specified in the join clause, which populates the $user['activity'] array and $user['effective_last_activity'] entry, which you can see in use in the member_card template.
  3. Phases

    Phases Active Member

    Man I wish I understood that, lol. I sure tried, looked around. I found what you were talking about in member_card but that's it and it didn't give me any insight on what to do.

    I'm doing this top five over on wordpress - so I'm basically trying to just pull the information from the xf_user table straight from the database with a sql query. Is last_activity in there just not updated regularly or only certain things trigger it?

    Appreciate the response - don't spend too much time trying to straighten me out if they aren't quick and easy answers for you. Thanks.
  4. Kier

    Kier XenForo Developer Staff Member

    Last activity in the user table is updated periodically, but it's only safe to rely upon if the user is not currently online.

    If you want to pull the up-to-date info in a query, you need to look at the xf_session_activity table.
    Phases likes this.
  5. Phases

    Phases Active Member

    Excellent, thanks!

    Edit: Ok, rather than use that and show people who are trying to lurk around as well, I simply changed it to "Featured Active Users" and actually kinda like the random(ish) updating. But at any rate I needed to get that answer to understand for future use. Thanks again.

Share This Page