Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The default dashboard "last used" field is very expensive and should be removed #2514

Closed
vincentwoo opened this issue Dec 28, 2015 · 6 comments

Comments

@vincentwoo
Copy link
Contributor

In dashboard.rb, RailsAdmin does the following for every table by default:

@most_recent_changes[t.model.name] =
  t.first(sort: "#{t.table_name}.updated_at").try(:updated_at)

This is an ENORMOUSLY expensive call for any table that is not indexed on updated_at. For example, on my app:

coderpad-rails=# EXPLAIN SELECT  "pads".* FROM "pads"  ORDER BY pads.updated_at desc LIMIT 1;
                                 QUERY PLAN
----------------------------------------------------------------------------
 Limit  (cost=25411.89..25411.89 rows=1 width=1203)
   ->  Sort  (cost=25411.89..25811.53 rows=159859 width=1203)
         Sort Key: updated_at
         ->  Seq Scan on pads  (cost=0.00..24612.59 rows=159859 width=1203)
(4 rows)

This is occasionally causing complete HTTP timeouts in my application. I don't want to add an index just to service this dashboard, either. I'm going to turn off statistics entirely because there doesn't seem to be a way to disable just this behavior, but I'd recommend either adding a flag or just showing something much easier, like the created_at time on the last row in the table.

@nynhex
Copy link

nynhex commented Jan 27, 2016

@vincentwoo I'm having the exact same problem in both old versions of rails_admin and new versions. It's super expensive to load the stats page and often my app will timeout for 2-4min at a same.

Is there any way to disable the stats to avoid these expensive calls?

@codealchemy
Copy link
Contributor

@shakycode The stats bar can be disabled (more on that here):

RailsAdmin.config do |c|
  c.actions do
    dashboard do
      statistics false
    end
  end
end

You could also build your own custom dashboard in app/views/rails_admin/main/dashboard.html.erb (or .haml, depending on your project)

@vincentwoo
Copy link
Contributor Author

I did that as well, but I think it is not a good default for rails_admin to have.

@bbenezech
Copy link
Collaborator

What should we do instead?
Is the sorting important?
If not, maybe you can provide a pull request sorting by id?

@vincentwoo
Copy link
Contributor Author

I can. Are you open to that idea?

@bbenezech
Copy link
Collaborator

Sure!
We'll call it "last entries" instead of "last updates" I guess. 👯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants