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

improve performance for n+1s #817

Merged
merged 3 commits into from
May 2, 2017
Merged

Conversation

BenMorganIO
Copy link
Collaborator

@BenMorganIO BenMorganIO commented Apr 4, 2017

This guy solves some n+1 problems in the application. The solution is global. I need to take time though to scope the n+1s down to just what attribute constants we're actually using.

Tried using COLLECTION_ATTRIBUTES but that didn't work out very well. Didn't remove a single n+1. As per n+1 issues, I think sticking to ATTRIBUTE_TYPES is a good first step. I think we should integrate this with Administate::Page::Collection.


dashboard.class::ATTRIBUTE_TYPES.map do |key, value|
key if association_classes.include?(value) ||
association_classes.include?(value.try :deferred_class)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 4 (not 7) spaces for indenting a condition in an if statement spanning multiple lines.
Add parentheses to nested method call value.try :deferred_class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a little messy. Maybe we can split the checking here into one line, the try to another?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think was thinking of doing that. I'm going to take another stab at this.

@@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
def index
search_term = params[:search].to_s.strip
resources = Administrate::Search.new(resource_resolver, search_term).run
resources = resources.includes(*resource_includes) if resource_includes.any?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [82/80]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this really looks like it needs to be moved to the Administrate::Page::Collection model.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try that and see how it goes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I thought about moving it to the collection class, but that didn't work out the way I thought it would. Instead, it's been moved to the dashboard and we pass the includes from there.

@kevinelliott
Copy link

I would love to see this make it in.

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

Successfully merging this pull request may close these issues.

4 participants