Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Caching primary_key_for_sphinx - can get a little expensive otherwise.

  • Loading branch information...
commit 702c8a210ba28ff463d700c06f45352dd50b41ec 1 parent 6d2e881
@pat pat authored
View
15 lib/thinking_sphinx/active_record.rb
@@ -24,10 +24,13 @@ def set_sphinx_primary_key(attribute)
end
def primary_key_for_sphinx
- if custom_primary_key_for_sphinx?
- @sphinx_primary_key_attribute || superclass.primary_key_for_sphinx
- else
- primary_key
+ @primary_key_for_sphinx ||= begin
+ if custom_primary_key_for_sphinx?
+ @sphinx_primary_key_attribute ||
+ superclass.primary_key_for_sphinx
+ else
+ primary_key
+ end
end
end
@@ -38,6 +41,10 @@ def custom_primary_key_for_sphinx?
) || !@sphinx_primary_key_attribute.nil?
end
+ def clear_primary_key_for_sphinx
+ @primary_key_for_sphinx = nil
+ end
+
def sphinx_index_options
sphinx_indexes.last.options
end
View
4 spec/thinking_sphinx/active_record_spec.rb
@@ -389,6 +389,10 @@
end
after :each do
+ Person.clear_primary_key_for_sphinx
+ end
+
+ after :each do
Person.set_sphinx_primary_key nil
end
Please sign in to comment.
Something went wrong with that request. Please try again.