mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 04:41:25 +08:00
PERF: reduce queries required for post timings
- also freezes a bunch of strings - bypass active record for an exists query
This commit is contained in:
@ -77,22 +77,26 @@ describe UserStat do
|
||||
let(:stat) { user.user_stat }
|
||||
|
||||
it 'makes no changes if nothing is cached' do
|
||||
stat.expects(:last_seen_cached).returns(nil)
|
||||
$redis.del(UserStat.last_seen_key(user.id))
|
||||
stat.update_time_read!
|
||||
stat.reload
|
||||
expect(stat.time_read).to eq(0)
|
||||
end
|
||||
|
||||
it 'makes a change if time read is below threshold' do
|
||||
stat.expects(:last_seen_cached).returns(Time.now - 10)
|
||||
freeze_time
|
||||
UserStat.cache_last_seen(user.id, (Time.now - 10).to_f)
|
||||
stat.update_time_read!
|
||||
stat.reload
|
||||
expect(stat.time_read).to eq(10)
|
||||
end
|
||||
|
||||
it 'makes no change if time read is above threshold' do
|
||||
freeze_time
|
||||
|
||||
t = Time.now - 1 - UserStat::MAX_TIME_READ_DIFF
|
||||
stat.expects(:last_seen_cached).returns(t)
|
||||
UserStat.cache_last_seen(user.id, t.to_f)
|
||||
|
||||
stat.update_time_read!
|
||||
stat.reload
|
||||
expect(stat.time_read).to eq(0)
|
||||
|
Reference in New Issue
Block a user