-
Notifications
You must be signed in to change notification settings - Fork 0
Implement caching for Question page #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
54ab2c6
92fd394
e543db1
b2c1468
0372a4a
1bae3d6
7d6345d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,4 @@ module RateablePolicy | |
| def rate? | ||
| admin? || user? && !owner? | ||
| end | ||
|
|
||
| def rate_revoke? | ||
| admin? || owner? | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| p id="comment-#{comment.id}" | ||
| = comment.body | ||
| span.little style="color:gray" | ||
| ' | ||
| ' — | ||
| => comment.user.email | ||
| ' at | ||
| = l comment.created_at, format: :short | ||
| hr style="margin:0 0 8px 0" | ||
| - cache [:comment_form, comment] do | ||
| p id="comment-#{comment.id}" | ||
| = comment.body | ||
| span.little style="color:gray" | ||
| ' | ||
| ' — | ||
| => comment.user.email | ||
| ' at | ||
| = l comment.created_at, format: :short | ||
| hr style="margin:0 0 8px 0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,36 @@ | ||
| div id="answer-#{answer.id}" class="#{answer.starred ? 'answer-starred' : ''}" | ||
| .row | ||
| .col-xs-12 | ||
| - if answer.starred | ||
| p.best-answer | ||
| strong Best Answer: | ||
| .pull-right id="answer-buttons-#{answer.id}" | ||
| - if comet | ||
| javascript: | ||
| $("#answer-buttons-#{answer.id}").html(JST["answer_buttons"]({ | ||
| question_id: "#{answer.question.id}", | ||
| question_user_id: "#{answer.question.user.id}", | ||
| answer_id: "#{answer.id}", | ||
| answer_user_id: "#{answer.user.id}" | ||
| })); | ||
| - else | ||
| - if policy(answer).destroy? | ||
| => link_to 'Delete', answer_path(answer), id: "delete-answer-#{answer.id}", class: "btn btn-danger btn-sm", method: :delete, remote: true | ||
| - if policy(answer).edit? | ||
| => link_to 'Edit', '#', id: "edit-answer-link-#{answer.id}", class: "btn btn-info btn-sm edit-answer-link", data: {answer_id: answer.id} | ||
| - if policy(answer).star? | ||
| = link_to 'Star', star_answer_path(answer), id: "star-answer-link-#{answer.id}", class: "btn btn-warning btn-sm star-answer-link", data: {answer_id: answer.id}, method: :patch, remote: true | ||
| = render 'shared/rating', rateable: answer | ||
| blockquote | ||
| = answer.body | ||
| = render 'questions/attachments', attachable: answer | ||
| = render 'comments/list', commentable: answer, comet: false | ||
| - if policy(answer).update? | ||
| div | ||
| = form_for answer, remote: true do |f| | ||
| = f.label :body, 'Answer' | ||
| .little id="answer-errors-#{answer.id}" | ||
| = f.text_area :body, class: 'form-control' | ||
| = f.submit 'Save', class: "btn btn-info btn-sm pull-right" | ||
| hr | ||
| - cache [answer, policy(answer).edit?, policy(answer).destroy?, policy(answer).star?, comet] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Идея хорошая, но в данном случае разве нельзя ограничится чем-то одним из
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Да можно в принципе, ключи типа "Answer и 3 boolean-а" нигде не используются больше, но это скорее с целью предусмотреть "на будущее", если вдруг они станут не равны -- формально мы же их так и проверяем разными в паршиале. Тем более, что длина ключа особо не влияет ни на что, так что решил формально учесть, как было, например, с политикой на подписку. |
||
| div id="answer-#{answer.id}" class="#{answer.starred ? 'answer-starred' : ''}" | ||
| .row | ||
| .col-xs-12 | ||
| - if answer.starred | ||
| p.best-answer | ||
| strong Best Answer: | ||
| .pull-right id="answer-buttons-#{answer.id}" | ||
| - if comet | ||
| javascript: | ||
| $("#answer-buttons-#{answer.id}").html(JST["answer_buttons"]({ | ||
| question_id: "#{answer.question.id}", | ||
| question_user_id: "#{answer.question.user.id}", | ||
| answer_id: "#{answer.id}", | ||
| answer_user_id: "#{answer.user.id}" | ||
| })); | ||
| - else | ||
| - if policy(answer).destroy? | ||
| => link_to 'Delete', answer_path(answer), id: "delete-answer-#{answer.id}", class: 'btn btn-danger btn-sm', method: :delete, remote: true | ||
| - if policy(answer).edit? | ||
| => link_to 'Edit', '#', id: "edit-answer-link-#{answer.id}", class: 'btn btn-info btn-sm edit-answer-link', data: {answer_id: answer.id} | ||
| - if policy(answer).star? | ||
| = link_to 'Star', star_answer_path(answer), id: "star-answer-link-#{answer.id}", class: 'btn btn-warning btn-sm star-answer-link', data: {answer_id: answer.id}, method: :patch, remote: true | ||
| = render 'shared/rating', rateable: answer | ||
| blockquote | ||
| = answer.body | ||
| = render 'questions/attachments', attachable: answer | ||
| = render 'comments/list', commentable: answer, comet: false | ||
| - if policy(answer).edit? | ||
| div | ||
| = form_for answer, remote: true do |f| | ||
| = f.label :body, 'Answer' | ||
| .little id="answer-errors-#{answer.id}" | ||
| = f.text_area :body, class: 'form-control' | ||
| = f.submit 'Save', class: 'btn btn-info btn-sm pull-right' | ||
| hr | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,32 @@ | ||
| div id="question-#{question.id}" | ||
| row | ||
| .col-sm-10 | ||
| p.lead | ||
| = link_to question_path(question) | ||
| = question.topic | ||
| - if policy(question).update? | ||
| div | ||
| = form_for question, remote: true do |f| | ||
| .little id="question-errors-#{question.id}" | ||
| = f.label :topic, 'Topic' | ||
| = f.text_field :topic, class: 'form-control' | ||
| = f.label :body, 'Question' | ||
| = f.text_area :body, class: 'form-control' | ||
| = f.submit 'Save', class: "btn btn-info btn-sm pull-right" | ||
| .col-sm-2 | ||
| .pull-right id="question-buttons-#{question.id}" | ||
| - if comet | ||
| javascript: | ||
| $("#question-buttons-#{question.id}").html(JST["question_buttons"]({ | ||
| question_id: "#{question.id}", | ||
| question_user_id: "#{question.user.id}" | ||
| })); | ||
| - else | ||
| - if policy(question).edit? | ||
| = link_to 'Edit', '#', id: "edit-question-link-#{question.id}", class: "btn btn-info btn-sm edit-question-link pull-right", data: {question_id: question.id} | ||
| = render 'shared/rating', rateable: question | ||
| row | ||
| .col-xs-12 | ||
| hr | ||
| - cache [question, policy(question).update?, comet] | ||
| div id="question-#{question.id}" | ||
| .row | ||
| .col-sm-10 | ||
| p.lead | ||
| = link_to question_path(question) | ||
| = question.topic | ||
| - if policy(question).update? | ||
| div | ||
| = form_for question, remote: true do |f| | ||
| .little id="question-errors-#{question.id}" | ||
| = f.label :topic, 'Topic' | ||
| = f.text_field :topic, class: 'form-control' | ||
| = f.label :body, 'Question' | ||
| = f.text_area :body, class: 'form-control' | ||
| = f.submit 'Save', class: "btn btn-info btn-sm pull-right" | ||
| .col-sm-2 | ||
| .pull-right id="question-buttons-#{question.id}" | ||
| - if comet | ||
| javascript: | ||
| $("#question-buttons-#{question.id}").html(JST["question_buttons"]({ | ||
| question_id: "#{question.id}", | ||
| question_user_id: "#{question.user.id}" | ||
| })); | ||
| - else | ||
| - if policy(question).edit? | ||
| = link_to 'Edit', '#', id: "edit-question-link-#{question.id}", \ | ||
| class: 'btn btn-info btn-sm edit-question-link pull-right', data: {question_id: question.id} | ||
| = render 'shared/rating', rateable: question | ||
| .row | ||
| .col-xs-12 | ||
| hr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше кэш переместить внутрь самого паршла, чтобы можно было и в других местах его же использовать.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пожалуй, да, и першаиал не имеет логики, и в свете предыдущей правки это логично.