Vote #79718
完了Performance improvement when rendering news or calendar block on My page
開始日:
2022/05/09
期日:
進捗率:
0%
予定工数:
Redmineorg_URL:
category_id:
53
version_id:
127
issue_org_id:
30249
author_id:
332
assigned_to_id:
332
comments:
3
status_id:
5
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
説明
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.
bench.rb
$ 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
journals
lgtm
--------------------------------------------------------------------------------
Pavel Rosický wrote:
> lgtm
Thank you for reviewing the patch. Setting the target version to 4.1.0.
--------------------------------------------------------------------------------
Committed.
--------------------------------------------------------------------------------
いいね!0