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
FIX: delete solution with post #256
Conversation
plugin.rb
Outdated
@@ -77,6 +77,7 @@ class Engine < ::Rails::Engine | |||
AUTO_CLOSE_TOPIC_TIMER_CUSTOM_FIELD = "solved_auto_close_topic_timer_id" | |||
ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD = "accepted_answer_post_id" | |||
ENABLE_ACCEPTED_ANSWERS_CUSTOM_FIELD = "enable_accepted_answers" | |||
IS_ACCEPTED_ASNWER_CUSTOM_FIELD = "is_accepted_answer" |
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.
Added this constant so we don't keep referencing the "is_accepted_answer"
string everywhere.
@@ -257,12 +259,18 @@ def limit_accepts | |||
|
|||
Discourse::Application.routes.append { mount ::DiscourseSolved::Engine, at: "solution" } | |||
|
|||
on(:post_destroyed) do |post| |
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.
This is the gist of the PR. We listen to the post_destroyer
event so we can properly "unaccept" an answer.
postInfo[2] = if SiteSetting.solved_quote_length > 0 | ||
PrettyText.excerpt(postInfo[2], SiteSetting.solved_quote_length, keep_emoji_images: true) | ||
post_info = | ||
if post = object.posts.find { |p| p.post_number == accepted_answer_post_id } |
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.
This is the "performance" change which looks up the stream for the post that is marked as the solution before doing a request to the database.
end | ||
) | ||
postInfo | ||
post_info[3] = nil if !SiteSetting.enable_names || !SiteSetting.display_name_on_posts |
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.
Feels like it's clearer to "just" set to nil
when names are disabled.
@@ -268,6 +268,23 @@ | |||
expect(p1.custom_fields["is_accepted_answer"]).to eq("true") | |||
end | |||
|
|||
it "removes the solution when the post is deleted" do |
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.
The test for the gist of the PR
topic&.custom_fields[::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD].present? | ||
end | ||
|
||
def topic |
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.
Tiny refactor for improved readability.
e85055c
to
812aa95
Compare
Ensures we remove the solution when the post marked as the solution is deleted. DEV: Added `IS_ACCEPTED_ANSWER_CUSTOM_FIELD` constant. DEV: Refactored the `PostSerializer` for better readability. PERF: Improved the `TopicViewSerializer`'s performance by looking up the `accepted_answer_post_info` from the stream first. Internal ref. dev/112251
812aa95
to
f939606
Compare
Ensures we remove the solution when the post marked as the solution is deleted.
DEV: Added
IS_ACCEPTED_ASNWER_CUSTOM_FIELD
constant.DEV: Refactored the
PostSerializer
for better readability.PERF: Improved the
TopicViewSerializer
's performance by looking up theaccepted_answer_post_info
from the stream first.Internal ref. dev/112251