PERF: bail out of expensive post validations

Whenever a post already failed "lightweight" validations, we skip all the expensive validations (that cooks the post or run SQL queries) so that we reply as soon as possible.

Also skip validating polls when there's no "[/poll]" in the raw.

Internal ref - t/115890
This commit is contained in:
Régis Hanol
2024-05-07 18:56:16 +02:00
parent 49661d7098
commit 12cba2ce24
4 changed files with 223 additions and 182 deletions
+3
View File
@@ -318,6 +318,9 @@ class DiscoursePoll::Poll
# creation process. `raw` could be nil here.
return [] if raw.blank?
# bail-out early if the post does not contain a poll
return [] if !raw.include?("[/poll]")
# TODO: we should fix the callback mess so that the cooked version is available
# in the validators instead of cooking twice
raw = raw.sub(%r{\[quote.+/quote\]}m, "")