プロジェクト

全般

プロフィール

Vote #80943

完了

evaluate acts_as_activity_provider's scope lazily

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Performance_53
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
53
version_id:
152
issue_org_id:
33664
author_id:
123153
assigned_to_id:
332
comments:
6
status_id:
5
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

acts_as_activity_provider's scope is evaluated at require time, we should build the scope after it's actually used


journals

Would you tell me how the patch will change the performance or user experience?
--------------------------------------------------------------------------------
sure, building a new scope is an expensive operation https://github.com/rails/rails/blob/5-2-stable/activerecord/lib/active_record/scoping/named.rb#L14

in this case, the scope for acts_as_activity_provider should be used after someone asks to get activities on issues for instance

however, right now we have to build a new scope when someone asks to require an issue object. This problem is usually hidden because Rails also does have an autoloading feature (at least in development mode).

before the patch, it does happen
1/ after autoloading an object model, let's say for opening an issue's detail shouldn't be necessary to build a scope for issue's activities, it's still too early
2/ in production mode due to eager loading
3/ if you have a simple plugin with a model patch (like issue_patch.rb). In this case, you have to always load the model (issue.rb) at start-up time

let's defer such operations as late as possible.

after the patch
I do register a proc which doesn't evaluate its content at require time and call it only when we need it (after someone asks for activities)
https://github.com/redmine/redmine/blob/907e0173e40b31d8d0e696b15b18777af98ec9da/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb#L54

this patch won't give you a better runtime performance, but it could improve startup time in some situations

note that for the same reason Rails also does define scopes lazily
https://github.com/redmine/redmine/blob/master/app/models/issue.rb#L86
* correct
<pre>scope :recently_updated, lambda { order(:updated_on => :desc) }</pre>
* wrong
<pre>scope :recently_updated, order(:updated_on => :desc)</pre>

that's what is this change about.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Setting the target version to 4.2.0.
--------------------------------------------------------------------------------
Updated the patch to fix some RuboCop offenses.
--------------------------------------------------------------------------------
Committed the patch. Thank you.
--------------------------------------------------------------------------------

Admin Redmine さんが3年以上前に更新

  • カテゴリPerformance_53 にセット
  • 対象バージョン4.2.0_152 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0