Actions
Patch #30249
closedPerformance improvement when rendering news or calendar block on My page
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
Actions