Skip to content

Commit

Permalink
Merge pull request #2982 from dalpo/dashboard-optimizations
Browse files Browse the repository at this point in the history
Dashboard audit improvements
  • Loading branch information
mshibuya authored Feb 17, 2018
2 parents a5ed925 + 8e7e9bc commit bf8e911
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/rails_admin/config/actions/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ class Dashboard < RailsAdmin::Config::Actions::Base
nil
end

register_instance_option :auditing_versions_limit do
50
end

register_instance_option :controller do
proc do
@history = @auditing_adapter && @auditing_adapter.latest || []
@history = @auditing_adapter && @auditing_adapter.latest(@action.auditing_versions_limit) || []
if @action.statistics?
@abstract_models = RailsAdmin::Config.visible_models(controller: self).collect(&:abstract_model)

Expand Down
4 changes: 2 additions & 2 deletions lib/rails_admin/extensions/history/auditing_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def initialize(controller, user_class = User)
require 'rails_admin/extensions/history/history'
end

def latest
::RailsAdmin::History.latest
def latest(count = 100)
::RailsAdmin::History.latest(count)
end

def delete_object(object, model, user)
Expand Down
4 changes: 2 additions & 2 deletions lib/rails_admin/extensions/history/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class History < ActiveRecord::Base
default_scope { order('id DESC') }

class << self
def latest
limit(100)
def latest(count = 100)
limit(count)
end

def create_history_item(message, object, abstract_model, user)
Expand Down
6 changes: 4 additions & 2 deletions lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ def initialize(controller, user_class = 'User', version_class = '::Version')
end
end

def latest
@version_class.order('id DESC').limit(100).collect { |version| VersionProxy.new(version, @user_class) }
def latest(count = 100)
@version_class.
order(id: :desc).includes(:item).limit(count).
collect { |version| VersionProxy.new(version, @user_class) }
end

def delete_object(_object, _model, _user)
Expand Down

0 comments on commit bf8e911

Please sign in to comment.