Is `topic_users.last_visited_at` supposed to be updated on every visit?

I’m pretty sure I’m ready to call this a bug.

I’ve been trying to find out where last_visited_at is updated so far I have found:

  1. The spec successfully tests a call to TopicUser::track_visit updates the value.
  2. TopicUser::change - change in notification level watching/tracking etc)
  3. TopicUser::update_last_read - keeps track of the last read post.

The problem seems to be:

  1. There are no calls to TopicUser::track_visit outside of the spec.
  2. TopicUser::update_last_read only updates the last_visited_at value when:
  • “The user read at least one post in a topic that they haven’t viewed before”

I’m thinking that the following should be reviewed:

1. Should there be an explicit call when track_view is set when requesting the topic? I think there should be.
2. Change the UPDATE_TOPIC_USER_SQL to also update last_visited_at time as used in TopicUser::update_last_read so the value is kept up to date along with reading times.

3. There is a possibility that last_visited_at and first_visited_at are being set to NULL here when TopicUser::change tracking state changes:

But I don’t know enough / have a test environment to check for sure.

4. If point 3 above is not where the NULL is coming from there is either TopicUser rows being put in the table with initially last_visited_at and first_visited_at set to NULL or somewhere else they are being set to NULL.

Thoughts?