index-tanked 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ module IndexTanked
14
14
  def add_to_index_tank_after_save(fallback=true)
15
15
  if index_tanked.dependencies_changed?
16
16
  if Configuration.activerecord_queue
17
- Document.enqueue(id, self.class.name, index_tanked.document_for_batch_addition)
17
+ Document.create(:record_id => id, :model_name => self.class.name, :document => index_tanked.document_for_batch_addition)
18
18
  else
19
19
  add_to_index_tank(fallback)
20
20
  end
@@ -54,19 +54,6 @@ module IndexTanked
54
54
  end
55
55
  end
56
56
 
57
- def self.enqueue(record_id, model_name, document_hash)
58
- retries = 0
59
- begin
60
- delete_all(:record_id => record_id, :model_name => model_name, :locked_by => nil)
61
- rescue ActiveRecord::StatementInvalid => e
62
- if e.message.match(/deadlock/) && retries < 3
63
- retries += 1
64
- retry
65
- end
66
- end
67
- create(:record_id => record_id, :model_name => model_name, :document => document_hash)
68
- end
69
-
70
57
  def self.get_or_update_index_information(model_name)
71
58
  @model_list ||= {}
72
59
  @index_list ||= {}
@@ -106,6 +93,24 @@ module IndexTanked
106
93
  end
107
94
  end
108
95
 
96
+ def self.remove_duplicate_documents(documents)
97
+ documents.inject([]) do |documents, document|
98
+ duplicate_index = index_of_duplicate_document(documents, document)
99
+ if duplicate_index && (documents[duplicate_index][:fields][:timestamp] < document[:fields][:timestamp])
100
+ documents[duplicate_index] = document
101
+ else
102
+ documents << document
103
+ end
104
+ documents
105
+ end
106
+ end
107
+
108
+ def self.index_of_duplicate_document(document_array, document_to_index)
109
+ document_array.index do |doc|
110
+ doc[:docid] == document_to_index[:docid]
111
+ end
112
+ end
113
+
109
114
  def self.update_index_list(companion_key, class_companion)
110
115
  @index_list[companion_key] = class_companion unless @index_list[companion_key].present?
111
116
  end
@@ -41,7 +41,8 @@ module IndexTanked
41
41
  return number_locked if number_locked.zero?
42
42
  begin
43
43
  documents = Queue::Document.find_all_by_locked_by(@identifier)
44
- partitioned_documents = Queue::Document.partition_documents_by_companion_key(documents)
44
+ documents_without_duplicate_docids = Queue::Document.remove_duplicate_documents(documents)
45
+ partitioned_documents = Queue::Document.partition_documents_by_companion_key(documents_without_duplicate_docids)
45
46
  send_batches_to_indextank(partitioned_documents)
46
47
  documents_deleted = Queue::Document.delete_all(:locked_by => @identifier)
47
48
  log("#{documents_deleted} completed documents removed from queue.")
@@ -1,3 +1,3 @@
1
1
  module IndexTanked
2
- GEM_VERSION = '0.3.2'
2
+ GEM_VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: index-tanked
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Kittelson
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-06-20 00:00:00 -07:00
19
+ date: 2011-06-21 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency