mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Don't store post timings that are greater than the account lifetime
This commit is contained in:
parent
a57bbd5000
commit
eaf5d21c41
2 changed files with 19 additions and 1 deletions
|
@ -65,9 +65,11 @@ class PostTiming < ActiveRecord::Base
|
|||
def self.process_timings(current_user, topic_id, topic_time, timings)
|
||||
current_user.user_stat.update_time_read!
|
||||
|
||||
account_age_msecs = ((Time.now - current_user.created_at) * 1000.0)
|
||||
|
||||
highest_seen = 1
|
||||
timings.each do |post_number, time|
|
||||
if post_number >= 0
|
||||
if post_number >= 0 && time < account_age_msecs
|
||||
PostTiming.record_timing(topic_id: topic_id,
|
||||
post_number: post_number,
|
||||
user_id: current_user.id,
|
||||
|
|
|
@ -60,6 +60,22 @@ describe PostTiming do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'safeguard' do
|
||||
it "doesn't store timings that are larger than the account lifetime" do
|
||||
user = Fabricate(:user, created_at: 3.minutes.ago)
|
||||
post = Fabricate(:post)
|
||||
|
||||
PostTiming.process_timings(user, post.topic_id, 1, [[post.post_number, 123]])
|
||||
msecs = PostTiming.where(post_number: post.post_number, user_id: user.id).pluck(:msecs)[0]
|
||||
expect(msecs).to eq(123)
|
||||
|
||||
PostTiming.process_timings(user, post.topic_id, 1, [[post.post_number, 10.minutes.to_i * 1000]])
|
||||
msecs = PostTiming.where(post_number: post.post_number, user_id: user.id).pluck(:msecs)[0]
|
||||
expect(msecs).to eq(123)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'process_timings' do
|
||||
|
||||
# integration test
|
||||
|
|
Loading…
Reference in a new issue