Skip to content

Commit

Permalink
fix transmitter replace if no data
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Apr 28, 2013
1 parent 93984ee commit 09c84c6
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/sphinx/integration/transmitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ def initialize(record)
# Обновляет запись в сфинксе
def replace
self.class.rt_indexes(record.class) do |index|
data = transmitted_data(index)

query = Riddle::Query::Insert.new(index.rt_name, data.keys, data.values).replace!.to_sql
self.class.execute(query)

query = "UPDATE #{index.core_name} SET sphinx_deleted = 1 WHERE id = #{record.sphinx_document_id}"
self.class.execute(query)
if (data = transmitted_data(index))
query = Riddle::Query::Insert.new(index.rt_name, data.keys, data.values).replace!.to_sql
self.class.execute(query)

if Redis::Mutex.new(:full_reindex).locked?
query = Riddle::Query::Insert.new(index.delta_rt_name, data.keys, data.values).replace!.to_sql
query = "UPDATE #{index.core_name} SET sphinx_deleted = 1 WHERE id = #{record.sphinx_document_id}"
self.class.execute(query)

if Redis::Mutex.new(:full_reindex).locked?
query = Riddle::Query::Insert.new(index.delta_rt_name, data.keys, data.values).replace!.to_sql
self.class.execute(query)
end
end
end
end
Expand Down Expand Up @@ -99,6 +99,7 @@ def self.execute(query)
def transmitted_data(index)
sql = index.single_query_sql.gsub('%{ID}', record.id.to_s)
row = record.class.connection.execute(sql).first
return unless row
row.merge!(mva_attributes(index))

row.each do |key, value|
Expand Down

0 comments on commit 09c84c6

Please sign in to comment.