Project

General

Profile

Actions

Patch #44735

open

Use Array#intersect? in Watchable#watched_by?

Added by Go MAEDA 1 day ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Code cleanup/refactoring

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:

(self.watcher_user_ids & user_ids).any?

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:

watcher_user_ids.intersect?(user_ids)

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

No data to display

Actions

Also available in: Atom PDF