Project

General

Profile

Actions

Defect #40193

closed

Performance issue with email address auto-linking in the default ("none") formatter

Added by Vincent Robert 11 months ago. Updated 11 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Text formatting
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

We recently encountered a significant issue where a user created issues with very lengthy descriptions, including email addresses at the end. This scenario exposed a performance concern in the auto_mailto! method, leading to potential server overload and unavailable application.

The issue stems from the fact that the regular expression used in the auto_mailto! method is relatively slow when applied to large text, posing challenges for improvement.

Attached is a test case that replicates the problem, highlighting that text formatting is swift on extensive input without email addresses, but significantly slows down when the auto_mailto! method is involved.

To address this issue in our production environment, we've temporarily implemented a patch. While it may not be the most elegant piece of code, it effectively mitigates the problem we encountered. This solution prevents server timeouts when users attempt to render the affected issues:

diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb
index 6bd4d4c3f..be084f43c 100644
--- a/lib/redmine/wiki_formatting.rb
+++ b/lib/redmine/wiki_formatting.rb
@@ -159,6 +159,7 @@ module Redmine

       # Destructively replaces email addresses into clickable links
       def auto_mailto!(text)
+        return text if text.length > 10000
         text.gsub!(/([\w\.!#\$%\-+.\/]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do
           mail = $1
           if /<a\b[^>]*>(.*)(#{Regexp.escape(mail)})(.*)<\/a>/.match?(text)

Files

wiki_formatting_test.diff (20.5 KB) wiki_formatting_test.diff Vincent Robert, 2024-02-05 16:11
40193.patch (847 Bytes) 40193.patch Go MAEDA, 2024-02-06 09:35
Actions

Also available in: Atom PDF