A platform for community discussion. Free, open, simple.
FEATURE: Use the "time_read" stat to flag users as suspicious. (#12145)
Roman Rizzi95fb363c2a56
diff --git a/app/jobs/scheduled/enqueue_suspect_users.rb b/app/jobs/scheduled/enqueue_suspect_users.rbindex e056020f3c4..5f388328128 100644--- a/app/jobs/scheduled/enqueue_suspect_users.rb+++ b/app/jobs/scheduled/enqueue_suspect_users.rb@@ -16,7 +16,7 @@ module Jobs.joins(:user_profile, :user_stat).where("users.created_at <= ? AND users.created_at >= ?", 1.day.ago, 6.months.ago).where("LENGTH(COALESCE(user_profiles.bio_raw, user_profiles.website, '')) > 0")- .where("user_stats.posts_read_count <= 1 AND user_stats.topics_entered <= 1")+ .where("user_stats.posts_read_count <= 1 OR user_stats.topics_entered <= 1 OR user_stats.time_read < ?", 5.minutes.to_i).joins("LEFT OUTER JOIN reviewables r ON r.target_id = users.id AND r.target_type = 'User'").where('r.id IS NULL').joins(diff --git a/spec/jobs/enqueue_suspect_users_spec.rb b/spec/jobs/enqueue_suspect_users_spec.rbindex d3dbc79b589..40fa3fbd574 100644--- a/spec/jobs/enqueue_suspect_users_spec.rb+++ b/spec/jobs/enqueue_suspect_users_spec.rb@@ -12,7 +12,7 @@ describe Jobs::EnqueueSuspectUsers doendcontext 'with suspect users' do- fab!(:suspect_user) { Fabricate(:active_user, created_at: 1.day.ago) }+ let!(:suspect_user) { Fabricate(:active_user, created_at: 1.day.ago) }it 'creates a reviewable when there is a suspect user' dosubject.execute({})@@ -88,5 +88,21 @@ describe Jobs::EnqueueSuspectUsers doexpect(ReviewableUser.where(target: suspect_user).exists?).to eq(false)end++ it 'enqueues a suspect user with not enough time read' do+ suspect_user.user_stat.update!(posts_read_count: 2, topics_entered: 2, time_read: 1.minute.to_i)++ subject.execute({})++ expect(ReviewableUser.count).to eq(1)+ end++ it 'ignores users if their time read is higher than five minutes' do+ suspect_user.user_stat.update!(posts_read_count: 2, topics_entered: 2, time_read: 10.minutes.to_i)++ subject.execute({})++ expect(ReviewableUser.count).to eq(0)+ endendend