class LastSeen
def touch(member_id)
key = "last_seen:#{member_id}"
last = Redis.current.get(key)
now = Time.current.to_i
if last.nil? || (now - last.to_i) > 300
Redis.current.set(key, now)
Member.where(id: member_id).update_all(last_seen_at: Time.at(now))
end
end
end
Updating last_seen_at on every request creates hot rows and write amplification. Instead, track last seen in Redis and periodically flush to DB, or only write when the value meaningfully changes.