Skip to content

Commit 6400a68

Browse files
committed
Better code for performance
1 parent 24b3a6f commit 6400a68

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

app/api/v1/fey_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class FeyAPI < Base
1717
result[:h][0][:name] = term.name if term.lower_name != term.name
1818
term.descriptions.each do |description|
1919
description_hash = { f: description.content }
20-
description_hash[:e] = description.examples.map(&:content) if description.examples.present?
21-
description_hash[:s] = description.synonyms.alts.map(&:content) if description.synonyms.alts.present?
20+
description_hash[:e] = description.examples.pluck(:content) if description.examples.present?
21+
description_hash[:s] = description.synonyms.alts.pluck(:content) if description.synonyms.alts.present?
2222
result[:h][0][:d] << description_hash
2323
end
2424

app/api/v1/poinsot_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class PoinsotAPI < Base
1717
result[:h][0][:name] = term.name if term.lower_name != term.name
1818
term.descriptions.each do |description|
1919
description_hash = { f: description.content }
20-
description_hash[:e] = description.examples.map(&:content) if description.examples.present?
21-
description_hash[:s] = description.synonyms.alts.map(&:content) if description.synonyms.alts.present?
20+
description_hash[:e] = description.examples.pluck(:content) if description.examples.present?
21+
description_hash[:s] = description.synonyms.alts.pluck(:content) if description.synonyms.alts.present?
2222
description_hash[:type] = description.description_type if description.description_type.present?
2323
result[:h][0][:d] << description_hash
2424
end

app/api/v1/safolu_api.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class SafoluAPI < Base
1818
result[:h][0][:name] = term.name if term.lower_name != term.name
1919
term.descriptions.each do |description|
2020
description_hash = { f: description.content }
21-
description_hash[:e] = description.examples.map(&:content) if description.examples.present?
22-
description_hash[:s] = description.synonyms.alts.map(&:content) if description.synonyms.alts.present?
23-
description_hash[:r] = description.synonyms.refs.map(&:content) if description.synonyms.refs.present?
21+
description_hash[:e] = description.examples.pluck(:content) if description.examples.present?
22+
description_hash[:s] = description.synonyms.alts.pluck(:content) if description.synonyms.alts.present?
23+
description_hash[:r] = description.synonyms.refs.pluck(:content) if description.synonyms.refs.present?
2424
result[:h][0][:d] << description_hash
2525
end
2626

app/controllers/terms_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def show
2121
end
2222
id_case_statement.else(10000)
2323

24-
@dictionaries = Dictionary.where(id: @terms.map(&:dictionary_id).uniq).order(id_case_statement)
24+
@dictionaries = Dictionary.where(id: @terms.pluck(:dictionary_id).uniq).order(id_case_statement)
2525
session[:last_page] = request.url
2626
end
2727
end

app/models/term.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def self.ransackable_attributes(auth_object = nil)
7171

7272
def short_description
7373
Rails.cache.fetch("term-#{name}-#{Date.today}", expires_in: 6.hours) do
74-
term_ids = Term.select(:id).where(name: name).order(:dictionary_id).pluck(:id)
74+
term_ids = Term.where(name: name).order(:dictionary_id).pluck(:id)
7575

7676
arel_description = Description.arel_table
7777
case_statement = Arel::Nodes::Case.new(arel_description[:term_id])

0 commit comments

Comments
 (0)