Commit 5e126d2f1c48c59f761f33d7d7535d798aee8f1b
1 parent
9cc834e0
Exists in
master
and in
7 other branches
Added improvement performance in api on endpoint :id/propose.
Showing
2 changed files
with
8 additions
and
4 deletions
Show diff stats
lib/proposals_discussion_plugin/api.rb
1 | 1 | class ProposalsDiscussionPlugin::API < Grape::API |
2 | + use ProposalsDiscussionPlugin::ApiNewRelicInstrumenter | |
2 | 3 | |
3 | - | |
4 | 4 | resource :proposals_discussion_plugin do |
5 | 5 | |
6 | 6 | paginate per_page: 10, max_per_page: 20 |
... | ... | @@ -26,11 +26,11 @@ class ProposalsDiscussionPlugin::API < Grape::API |
26 | 26 | post ':id/propose' do |
27 | 27 | sanitize_params_hash(params) |
28 | 28 | |
29 | - parent_article = environment.articles.find(params[:id]) | |
29 | + parent_article = environment.articles.includes(:profile).find(params[:id]) | |
30 | 30 | |
31 | 31 | proposal_task = ProposalsDiscussionPlugin::ProposalTask.new |
32 | 32 | proposal_task.article = params[:article] |
33 | - proposal_task.article_parent_id = parent_article.id | |
33 | + proposal_task.article_parent = parent_article | |
34 | 34 | proposal_task.target = parent_article.profile |
35 | 35 | proposal_task.requestor = current_person |
36 | 36 | ... | ... |
lib/proposals_discussion_plugin/proposal_task.rb
... | ... | @@ -129,8 +129,12 @@ class ProposalsDiscussionPlugin::ProposalTask < Task |
129 | 129 | requestor.name if requestor |
130 | 130 | end |
131 | 131 | |
132 | + def article_parent=(parent) | |
133 | + @article_parent = parent | |
134 | + end | |
135 | + | |
132 | 136 | def article_parent |
133 | - Article.find_by_id article_parent_id.to_i | |
137 | + @article_parent ||= Article.find_by_id article_parent_id.to_i | |
134 | 138 | end |
135 | 139 | |
136 | 140 | def article_object | ... | ... |