mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
PERF: Tl3Promotions job can limit the number of TL3 candidates by using some simple requirements in the query
This commit is contained in:
parent
eefd226611
commit
d7e90edeb5
@ -21,13 +21,22 @@ module Jobs
|
||||
end
|
||||
|
||||
# Promotions
|
||||
User.real.where(
|
||||
trust_level: TrustLevel[2],
|
||||
manual_locked_trust_level: nil,
|
||||
group_locked_trust_level: nil
|
||||
).where.not(id: demoted_user_ids).find_each do |u|
|
||||
User.real.not_suspended.where(
|
||||
trust_level: TrustLevel[2],
|
||||
manual_locked_trust_level: nil,
|
||||
group_locked_trust_level: nil
|
||||
).where.not(id: demoted_user_ids)
|
||||
.joins(:user_stat)
|
||||
.where("user_stats.days_visited >= ?", SiteSetting.tl3_requires_days_visited)
|
||||
.where("user_stats.topic_reply_count >= ?", SiteSetting.tl3_requires_topics_replied_to)
|
||||
.where("user_stats.topics_entered >= ?", SiteSetting.tl3_requires_topics_viewed_all_time)
|
||||
.where("user_stats.posts_read_count >= ?", SiteSetting.tl3_requires_posts_read_all_time)
|
||||
.where("user_stats.likes_given >= ?", SiteSetting.tl3_requires_likes_given)
|
||||
.where("user_stats.likes_received >= ?", SiteSetting.tl3_requires_likes_received)
|
||||
.find_each do |u|
|
||||
Promotion.new(u).review_tl2
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2,10 +2,23 @@ require 'rails_helper'
|
||||
|
||||
describe Jobs::Tl3Promotions do
|
||||
|
||||
def create_qualifying_stats(user)
|
||||
user.create_user_stat if user.user_stat.nil?
|
||||
user.user_stat.update_attributes!(
|
||||
days_visited: 1000,
|
||||
topic_reply_count: 1000,
|
||||
topics_entered: 1000,
|
||||
posts_read_count: 1000,
|
||||
likes_given: 1000,
|
||||
likes_received: 1000
|
||||
)
|
||||
end
|
||||
|
||||
subject(:run_job) { described_class.new.execute({}) }
|
||||
|
||||
it "promotes tl2 user who qualifies for tl3" do
|
||||
_tl2_user = Fabricate(:user, trust_level: TrustLevel[2])
|
||||
create_qualifying_stats(_tl2_user)
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(true)
|
||||
Promotion.any_instance.expects(:change_trust_level!).with(TrustLevel[3], anything).once
|
||||
run_job
|
||||
@ -14,6 +27,8 @@ describe Jobs::Tl3Promotions do
|
||||
it "doesn't promote tl1 and tl0 users who have met tl3 requirements" do
|
||||
_tl1_user = Fabricate(:user, trust_level: TrustLevel[1])
|
||||
_tl0_user = Fabricate(:user, trust_level: TrustLevel[0])
|
||||
create_qualifying_stats(_tl1_user)
|
||||
create_qualifying_stats(_tl0_user)
|
||||
TrustLevel3Requirements.any_instance.expects(:requirements_met?).never
|
||||
Promotion.any_instance.expects(:change_trust_level!).never
|
||||
run_job
|
||||
|
Loading…
Reference in New Issue
Block a user