Patch #30249

Performance improvement when rendering news or calendar block on My page

Added by Go MAEDA about 1 month ago. Updated 28 days ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Performance
Target version:4.1.0

Description

The following patch improves the performance when retrieving objects to render especially when there are many visible projects.

Index: app/helpers/my_helper.rb
===================================================================
--- app/helpers/my_helper.rb    (revision 17763)
+++ app/helpers/my_helper.rb    (working copy)
@@ -78,7 +78,7 @@
   def render_calendar_block(block, settings)
     calendar = Redmine::Helpers::Calendar.new(User.current.today, current_language, :week)
     calendar.events = Issue.visible.
-      where(:project_id => User.current.projects.pluck(:id)).
+      where(:project => User.current.projects).
       where("(start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)", calendar.startdt, calendar.enddt, calendar.startdt, calendar.enddt).
       includes(:project, :tracker, :priority, :assigned_to).
       references(:project, :tracker, :priority, :assigned_to).
@@ -142,7 +142,7 @@

   def render_news_block(block, settings)
     news = News.visible.
-      where(:project_id => User.current.projects.pluck(:id)).
+      where(:project => User.current.projects).
       limit(10).
       includes(:project, :author).
       references(:project, :author).

Here is a result of the benchmark test. About 9 times faster with 1000 projects.

$ bin/rails r bench.rb
Warming up --------------------------------------
              before     5.000  i/100ms
               after    64.000  i/100ms
Calculating -------------------------------------
              before     68.797  (± 7.3%) i/s -    345.000  in   5.040461s
               after    652.797  (± 6.0%) i/s -      3.264k in   5.018461s

Comparison:
               after:      652.8 i/s
              before:       68.8 i/s - 9.49x  slower

Associated revisions

Revision 17771
Added by Go MAEDA 28 days ago

Performance improvement when rendering news or calendar block on My page (#30249).

Patch by Go MAEDA.

History

#1 Updated by Pavel Rosický 30 days ago

lgtm

#2 Updated by Go MAEDA 29 days ago

  • Target version set to 4.1.0

Pavel Rosický wrote:

lgtm

Thank you for reviewing the patch. Setting the target version to 4.1.0.

#3 Updated by Go MAEDA 28 days ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed.

Also available in: Atom PDF