Skip to content

Commit

Permalink
Fix lost backward compatibility about ProjectQuery#results_scope's re…
Browse files Browse the repository at this point in the history
…turn type
  • Loading branch information
nishidayuya committed Oct 27, 2024
1 parent 5313541 commit 5412626
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
19 changes: 9 additions & 10 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def reload(*args)
@override_members = nil
@assignable_users = nil
@last_activity_date = nil
self.class.clear_last_activities
base_reload(*args)
end

Expand Down Expand Up @@ -1009,18 +1010,16 @@ def visible_custom_field_values(user = nil)
end
end

def last_activity_date
@last_activity_date || fetch_last_activity_date
def self.last_activities
@last_activities ||= Redmine::Activity::Fetcher.new(User.current).events(nil, nil, :last_by_project => true).to_h
end

# Preloads last activity date for a collection of projects
def self.load_last_activity_date(projects, user=User.current)
if projects.any?
last_activities = Redmine::Activity::Fetcher.new(User.current).events(nil, nil, :last_by_project => true).to_h
projects.each do |project|
project.instance_variable_set(:@last_activity_date, last_activities[project.id])
end
end
def self.clear_last_activities
@last_activities = nil
end

def last_activity_date
self.class.last_activities[id] || fetch_last_activity_date
end

private
Expand Down
8 changes: 1 addition & 7 deletions app/models/project_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@ def results_scope(options={})
if has_column?(:parent_id)
scope = scope.preload(:parent)
end

projects = scope.to_a
if has_column?(:last_activity_date)
Project.load_last_activity_date(scope)
end

projects
scope
end
end

0 comments on commit 5412626

Please sign in to comment.