VRFS-736 consolidating query
This commit is contained in:
parent
1271b74bc4
commit
f6196bb2c8
|
|
@ -96,15 +96,16 @@ module JamRuby
|
|||
["#{date_column} < ?", Time.now - intervals[trigger_idx].days]
|
||||
end
|
||||
|
||||
|
||||
def fetch_client_notdl(trigger_idx=0)
|
||||
fetched = []
|
||||
rel = User
|
||||
.email_opt_in
|
||||
.musicians
|
||||
.where("(((SELECT MAX(trigger_index) FROM email_batch_sets ebs WHERE ebs.sub_type = '#{self.sub_type}' AND ebs.user_id = users.id) < #{trigger_idx}) OR ((SELECT COUNT(*) FROM email_batch_sets ebs WHERE ebs.sub_type = '#{self.sub_type}' AND ebs.user_id = users.id) = 0))")
|
||||
.where("(SELECT COALESCE(MAX(trigger_index),-1) FROM email_batch_sets ebs WHERE ebs.sub_type = '#{self.sub_type}' AND ebs.user_id = users.id) < #{trigger_idx}")
|
||||
.where("first_downloaded_client_at IS NULL")
|
||||
.where(self.trigger_date_constraint(trigger_idx, "users.created_at"))
|
||||
.find_in_batches(batch_size: 100) do |users|
|
||||
.find_in_batches(batch_size: 500) do |users|
|
||||
block_given? ? yield(users) : fetched.concat(users)
|
||||
end
|
||||
fetched
|
||||
|
|
|
|||
|
|
@ -41,5 +41,15 @@ module JamRuby
|
|||
''
|
||||
end
|
||||
|
||||
def previous_trigger_date
|
||||
return nil if 0 == self.trigger_index.to_i || self.user_id.nil?
|
||||
self.class
|
||||
.where(['email_batch__id = ? AND user_id = ? AND sub_type = ? AND trigger_index = ?',
|
||||
self.email_batch_id, self.user_id, self.sub_type, self.trigger_index - 1])
|
||||
.pluck(:created_at)
|
||||
.limit(1)
|
||||
.first
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ describe EmailBatch do
|
|||
end
|
||||
|
||||
it 'progressively returns expected count' do
|
||||
user_; user_trigger0; user_trigger1
|
||||
Timecop.travel(user_trigger2.created_at + batchp.days_past_for_trigger_index(0).days)
|
||||
expect(batchp.fetch_client_notdl(0).count).to eq(1)
|
||||
batchp.make_set(user_trigger2, 0)
|
||||
|
|
@ -110,6 +111,22 @@ describe EmailBatch do
|
|||
expect(batchp.fetch_client_notdl(2).count).to eq(1)
|
||||
end
|
||||
|
||||
it 'handles skips properly' do
|
||||
Timecop.travel(user_trigger2.created_at + batchp.days_past_for_trigger_index(0).days)
|
||||
expect(batchp.fetch_client_notdl(0).count).to eq(1)
|
||||
batchp.make_set(user_trigger2, 0)
|
||||
Timecop.travel(user_trigger2.created_at + batchp.days_past_for_trigger_index(2).days)
|
||||
expect(batchp.fetch_client_notdl(1).count).to eq(1)
|
||||
batchp.make_set(user_trigger2, 1)
|
||||
Timecop.travel(user_trigger2.created_at + batchp.days_past_for_trigger_index(1).days)
|
||||
expect(batchp.fetch_client_notdl(1).count).to eq(0)
|
||||
# expect(batchp.fetch_client_notdl(2).count).to eq(1)
|
||||
end
|
||||
|
||||
it 'runs every day' do
|
||||
pending
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue