pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 468 forks source link

Delayed delta on every save #272

Closed abonec closed 12 years ago

abonec commented 13 years ago

Hello. I use thinking-sphinx 2.0.4 and on every save model (by .save) ts has added new delayed job to index delta. I go through source and find out that my problem in this piece of code: https://github.com/freelancing-god/thinking-sphinx/blob/061e292556eb639bb20e1e708cf824267d8f8ef8/lib/thinking_sphinx/property.rb#L66

Column with attributes has name like 15987636 or 0 that I not defined in "define_index" method and this attributes in line 67 and 68 fail because my model not have method like "15987636_changed?" and "0_changed?".

My TS defined is here: define_index do indexes title indexes body_html indexes blog.title, :as => :blog_title where "posts.state = 'published'" has blog_id, blog_type set_property :field_weights => { :title => 10, :body_html => 5, :blog_title => 1 } set_property :delta => :delayed end Why TS have 15987636 and 0 attributes?

pat commented 13 years ago

Hi Alexander

Those two attributes are named class_crc and sphinx_deleted - internal attributes for Thinking Sphinx. The first is for determining which class the Sphinx result is an instance of, and the second is for hiding results that have been deleted in the Rails app since the most recent indexing.

I'm not sure why you're getting that failure, as it should not be using the values to determine whether they've changed, but the names. Can you provide the error and backtrace?

abonec commented 13 years ago

Hello. I was wrong. Problem is not in TS, it is in ts-delayed-delta. When I save my model on every save TSDD add job to index delta even if I just do "Post.last.save". Post.changed in this situation return false.

Can you provide the error and backtrace? It is not an error it just add delayed job on every save and no matter changed model or not.

pat commented 13 years ago

What does your define_index block look like in your Post model?

abonec commented 13 years ago

In first post I posted define_index block. Association blog - it is polimorphic to few other models.

pat commented 13 years ago

Ah, of course - sorry, I wasn't particularly awake when I answered this morning.

The reason indexing always happens is because you're using an association - so Thinking Sphinx can't be sure whether data has changed or not. Hence, it fires an index request just in case.

abonec commented 13 years ago

When I delete this lines: indexes blog.title, :as => :blog_title where "posts.state = 'published'" has blog_id, blog_type It is still add job on every save =( And is there way to control this behavior from model?

pat commented 13 years ago

Ah, I think I've found the bug in ts-delayed-delta - can you give the latest from Github a spin instead of the most recent gem release?

You can manually request edits to not fire delta updates if you wish:

Post.suspended_delta(false) { post.save }