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:
Sam
2018-01-17 15:49:35 +11:00
parent 8c47eb2951
commit b7023da894
3 changed files with 43 additions and 26 deletions

View File

@ -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)