Skip to content

Commit

Permalink
Removed redundant database calls
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoynter committed May 26, 2017
1 parent e14e49a commit ed85f32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/variables_controller.rb
Expand Up @@ -50,6 +50,6 @@ def collection
end

def set_dataset
@dataset = policy_scope(Dataset).find(params[:dataset_id])
@dataset = policy_scope(Dataset).includes(variables: [:questions, :src_variables, :der_variables, :topic] ).find(params[:dataset_id])
end
end
7 changes: 6 additions & 1 deletion app/views/variables/index.json.jbuilder
Expand Up @@ -8,7 +8,12 @@ json.array!(@collection) do |variable|
json.used_bys variable.der_variables, :id, :name, :label, :var_type
json.topic variable.topic, :id, :code, :name, :parent_id unless variable.topic.nil?
json.strand do
json.topic variable.strand.topic, :id, :code, :name, :parent_id
json.topic do
json.id = variable.strand.topic.id
json.code = variable.strand.topic.code
json.name = variable.strand.topic.name
json.parent_id = variable.strand.topic.parent_id
end
json.good variable.strand.good
end unless variable.strand.topic.nil?
json.suggested_topic variable.get_suggested_topic, :id, :code, :name, :parent_id unless variable.get_suggested_topic.nil?
Expand Down

0 comments on commit ed85f32

Please sign in to comment.