Project

General

Profile

Actions

Patch #44735

closed

Use 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

Added by Go MAEDA 26 days ago. Updated 24 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Code cleanup/refactoring
Target version:

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

Updated by Go MAEDA 24 days ago Actions #1

  • Subject changed from Use Array#intersect? in Watchable#watched_by? to Use Array#intersect? in acts_as_watchable to avoid allocating an intermediate array
  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Target version changed from Candidate for next major release to 7.1.0

Committed the patch in r25456.

Actions

Also available in: PDF Atom