Project

General

Profile

Feature #23954 » last_activity-2.r3.4.patch

Performance patch for Redmine 3.4 - Frederico Camara, 2018-03-08 18:53

View differences:

app/helpers/admin_helper.rb
25 25
                        [l(:project_status_archived), '9']], selected.to_s)
26 26
  end
27 27

  
28
  def last_activities()
29
    Redmine::Activity::Fetcher.new(User.current).events(nil, nil, :last_by_project => true).to_h
30
  end
31

  
28 32
  def plugin_data_for_updates(plugins)
29 33
    data = {"v" => Redmine::VERSION.to_s, "p" => {}}
30 34
    plugins.each do |plugin|
app/views/admin/projects.html.erb
23 23
  <th><%=l(:label_project)%></th>
24 24
  <th><%=l(:field_is_public)%></th>
25 25
  <th><%=l(:field_created_on)%></th>
26
  <th><%=l(:field_last_activity)%></th>
26 27
  <th></th>
27 28
  </tr></thead>
28 29
  <tbody>
30
<% project_activities = last_activities %>
29 31
<% project_tree(@projects, :init_level => true) do |project, level| %>
30 32
  <tr class="<%= project.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
31 33
  <td class="name"><span><%= link_to_project_settings(project, {}, :title => project.short_description) %></span></td>
32 34
  <td><%= checked_image project.is_public? %></td>
33 35
  <td><%= format_date(project.created_on) %></td>
36
  <td><%= format_date(project_activities[project.id]) %></td>
34 37
  <td class="buttons">
35 38
    <%= link_to(l(:button_archive), archive_project_path(project, :status => params[:status]), :data => {:confirm => l(:text_are_you_sure)}, :method => :post, :class => 'icon icon-lock') unless project.archived? %>
36 39
    <%= link_to(l(:button_unarchive), unarchive_project_path(project, :status => params[:status]), :method => :post, :class => 'icon icon-unlock') if project.archived? && (project.parent.nil? || !project.parent.archived?) %>
config/locales/en.yml
258 258
  field_downloads: Downloads
259 259
  field_author: Author
260 260
  field_created_on: Created
261
  field_last_activity: Last activity
261 262
  field_updated_on: Updated
262 263
  field_closed_on: Closed
263 264
  field_field_format: Format
config/locales/pt-BR.yml
224 224
  field_downloads: Downloads
225 225
  field_author: Autor
226 226
  field_created_on: Criado em
227
  field_last_activity: Última atividade
227 228
  field_updated_on: Alterado em
228 229
  field_field_format: Formato
229 230
  field_is_for_all: Para todos os projetos
lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb
78 78
              scope = scope.where(Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options))
79 79
            end
80 80

  
81
            if options[:last_by_project]
82
              scope = scope.group("projects.id").maximum(provider_options[:timestamp])
83
            end
84

  
81 85
            scope.to_a
82 86
          end
83 87
        end
lib/redmine/activity/fetcher.rb
85 85
      def events(from = nil, to = nil, options={})
86 86
        e = []
87 87
        @options[:limit] = options[:limit]
88
        @options[:last_by_project] = options[:last_by_project] if options[:last_by_project]
88 89

  
89 90
        @scope.each do |event_type|
90 91
          constantized_providers(event_type).each do |provider|
......
92 93
          end
93 94
        end
94 95

  
95
        e.sort! {|a,b| b.event_datetime <=> a.event_datetime}
96
        if options[:last_by_project]
97
          e.sort
98
        else
99
          e.sort! {|a,b| b.event_datetime <=> a.event_datetime}
96 100

  
97
        if options[:limit]
98
          e = e.slice(0, options[:limit])
101
          if options[:limit]
102
            e = e.slice(0, options[:limit])
103
          end
99 104
        end
100 105
        e
101 106
      end
(4-4/9)