Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #951 from jdelStrother/develop
Reduce allocations in ActiveRecord callbacks
  • Loading branch information
pat committed Sep 29, 2015
2 parents 70c73d9 + c15bbe7 commit 6f1bcbb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
Expand Up @@ -29,7 +29,7 @@ def indices
@indices ||= begin
configuration.preload_indices
configuration.indices_for_references(
*@association.klass.name.underscore.to_sym
*ThinkingSphinx::IndexSet.reference_name(@association.klass)
).reject &:distributed?
end
end
Expand Down
Expand Up @@ -35,7 +35,7 @@ def indices
end

def reference
instance.class.name.underscore.to_sym
ThinkingSphinx::IndexSet.reference_name(instance.class)
end

def update(index)
Expand Down
7 changes: 6 additions & 1 deletion lib/thinking_sphinx/index_set.rb
@@ -1,5 +1,10 @@
class ThinkingSphinx::IndexSet
include Enumerable

def self.reference_name(klass)
@cached_results ||= {}
@cached_results[klass.name] ||= klass.name.underscore.to_sym
end

delegate :each, :empty?, :to => :indices

Expand Down Expand Up @@ -63,7 +68,7 @@ def indices_for_references

def references
options[:references] || classes_and_ancestors.collect { |klass|
klass.name.underscore.to_sym
ThinkingSphinx::IndexSet.reference_name(klass)
}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/middlewares/sphinxql.rb
Expand Up @@ -82,7 +82,7 @@ def descendants_from_tables

def indices_match_classes?
indices.collect(&:reference).uniq.sort == classes.collect { |klass|
klass.name.underscore.to_sym
ThinkingSphinx::IndexSet.reference_name(klass)
}.sort
end

Expand Down

0 comments on commit 6f1bcbb

Please sign in to comment.