Refactor Credit's array creation (#3116) [ci skip]

This commit is contained in:
Arun Kumar 2019-06-11 09:28:25 -05:00 committed by Mac Siri
parent 9414bb43ac
commit b34387f384
2 changed files with 3 additions and 12 deletions

View file

@ -45,10 +45,7 @@ module Api
else
%w[career discuss productivity]
end
@articles = []
4.times do
@articles << Suggester::Articles::Classic.new.get(tag_list)
end
@articles = Array.new(4) { Suggester::Articles::Classic.new.get(tag_list) }
Article.tagged_with(tag_list, any: true).
order("published_at DESC").
where("positive_reactions_count > ? OR comments_count > ? AND published = ?", 10, 3, true).

View file

@ -20,10 +20,7 @@ class Credit < ApplicationRecord
}
def self.add_to(user, amount)
credit_objects = []
amount.times do
credit_objects << Credit.new(user_id: user.id)
end
credit_objects = Array.new(amount) { Credit.new(user_id: user.id) }
Credit.import credit_objects
end
@ -32,10 +29,7 @@ class Credit < ApplicationRecord
end
def self.add_to_org(org, amount)
credit_objects = []
amount.times do
credit_objects << Credit.new(organization_id: org.id)
end
credit_objects = Array.new(amount) { Credit.new(organization_id: org.id) }
Credit.import credit_objects
end