Actions
Patch #44735
closedUse Array#intersect? in acts_as_watchable to avoid allocating an intermediate array
Patch #44735:
Use Array#intersect? in acts_as_watchable to avoid allocating an intermediate array
Description
The attached patch changes Redmine::Acts::Watchable::InstanceMethods#watched_by? to use Array#intersect?, which is available since Ruby 3.1.
The method currently checks whether a principal or any of its groups is among the watchers of an object as follows:
This builds an intermediate array that holds the intersection of the two arrays, only to check whether it is empty. Array#intersect? returns the same result without creating that array:
This also makes the method consistent with other places in Redmine that already use Array#intersect?, such as IssueCustomField#visible_by? and Query#visible?.
Files
Actions