xapian_db 1.3.7.4 → 1.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1979b59ffcc42e298d5696f7729c76e4e59394fc35e230c88c3bdbf0830279d7
4
- data.tar.gz: 672b7bbbe1c2e2833fc09e57e5bf8916bae46812c31608f122e7b9732d39af6f
3
+ metadata.gz: a219ad5e9648568bdf084f50f5639133fb493a5dd6ec44c59e2adb03102c4bdc
4
+ data.tar.gz: 472fa6a0894c26c46991d61cd891202aa444f92b661b2f3172856e050e6f30d5
5
5
  SHA512:
6
- metadata.gz: 3094d0d66b745bf3dee99f9569ada5239d990812c50a7c995fd588cd140ce8f11b659a504340ae345db17009dc1e2873d47b9934636989e4bdfe7851e113cdb5
7
- data.tar.gz: 9ff35b2818e51c8e7654f3ee4fae591a32c8cdf03c5ab7c99097a728df4ddaa4adadf5e04fbf9ea515ca9ae5b0fc7b55752835f9e80722a95039e28b6725828c
6
+ metadata.gz: 8f4084aed2f0fce0edc901f695d076d740a61b72ea8e2ccd9b7315af3b7b389478da74d176e2bebf019d8d7f57632595cdc9a436df875c9f5ad16541f49ae96f
7
+ data.tar.gz: 3f7463fab1bfdec7ff5c47306243c6c48ed10abfb0fbda970246bbc08289431e14c625ef6b98b53013182ac2ac5c9b07565739ec801f1e3add5f8720cf7f661a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 1.3.9 (October 26th, 2022)
2
+
3
+ Fixes:
4
+
5
+ - `XapianDb.execute_block` now uses `Thread.current[:xapian_db_block_writer]` to store its block-local writer as to avoid leaking into another Thread
6
+
7
+ ## 1.3.8 (July 19th, 2021)
8
+
9
+ Fixes:
10
+
11
+ - xapian docs are deleted in the after commit hook in order to respect transaction rollbacks
12
+
1
13
  ## 1.3.7.4 (October 27th, 2020)
2
14
 
3
15
  Changes:
data/README.rdoc CHANGED
@@ -61,7 +61,7 @@ You can override these defaults by placing a config file named 'xapian_db.yml' i
61
61
 
62
62
  # XapianDb configuration
63
63
  defaults: &defaults
64
- adapter: datamapper # Avaliable adapters: :active_record, :datamapper
64
+ adapter: datamapper # Available adapters: :active_record, :datamapper
65
65
  language: de # Global language; can be overridden for specific blueprints
66
66
  term_min_length: 2 # Ignore single character terms
67
67
  enabled_query_flags: FLAG_PHRASE, FLAG_SPELLING_CORRECTION
@@ -226,7 +226,8 @@ If you want to manage the (re)indexing of your objects on your own, turn off aut
226
226
  blueprint.autoindex false
227
227
  end
228
228
 
229
- This will turn off the auto-reindexing for any object of the configured class. Use XapianDb.reindex(object) to trigger the reindexing logic in your code. Please note that destroying an object will always remove it from the xapian index.
229
+ This will turn off the auto-reindexing for any object of the configured class. Use XapianDb.reindex(object) to trigger the reindexing logic in your code.
230
+ It will also turn off the auto-deletion of the doc, when the object gets destroyed. Use XapianDb.delete_doc_with(object.xapian_id) to trigger deletion logic in your code.
230
231
 
231
232
 
232
233
  Place these configurations either into the corresponding class or - I prefer to have the index configurations outside
@@ -48,19 +48,16 @@ module XapianDb
48
48
  klass.class_eval do
49
49
  # add the after commit logic, unless the blueprint has autoindexing turned off
50
50
  if XapianDb::DocumentBlueprint.blueprint_for(klass.name).autoindex?
51
- after_commit do
52
- unless self.destroyed?
53
- XapianDb.reindex(self, true, changed_attrs: self.previous_changes.keys)
54
- XapianDb::DocumentBlueprint.dependencies_for(klass.name, self.previous_changes.keys).each do |dependency|
55
- dependency.block.call(self).each{ |model| XapianDb.reindex model, true, changed_attrs: self.previous_changes.keys }
56
- end
51
+ after_commit on: [:create, :update] do
52
+ XapianDb.reindex(self, true, changed_attrs: self.previous_changes.keys)
53
+ XapianDb::DocumentBlueprint.dependencies_for(klass.name, self.previous_changes.keys).each do |dependency|
54
+ dependency.block.call(self).each{ |model| XapianDb.reindex model, true, changed_attrs: self.previous_changes.keys }
57
55
  end
58
56
  end
59
- end
60
57
 
61
- # add the after destroy logic
62
- after_destroy do
63
- XapianDb.delete_doc_with(self.xapian_id)
58
+ after_commit on: :destroy do
59
+ XapianDb.delete_doc_with(self.xapian_id)
60
+ end
64
61
  end
65
62
 
66
63
  # Add a method to reindex all models of this class
@@ -47,22 +47,22 @@ module XapianDb
47
47
  end
48
48
 
49
49
  klass.class_eval do
50
+ # add the after save/destroy logic, unless the blueprint has autoindexing turned off
51
+ if XapianDb::DocumentBlueprint.blueprint_for(klass.name).autoindex?
52
+ after :save do
53
+ blueprint = XapianDb::DocumentBlueprint.blueprint_for klass.to_s
54
+ if blueprint.should_index?(self)
55
+ XapianDb.index(self)
56
+ else
57
+ XapianDb.delete_doc_with(self.xapian_id)
58
+ end
59
+ end
50
60
 
51
- # add the after save logic
52
- after :save do
53
- blueprint = XapianDb::DocumentBlueprint.blueprint_for klass.to_s
54
- if blueprint.should_index?(self)
55
- XapianDb.index(self)
56
- else
61
+ after :destroy do
57
62
  XapianDb.delete_doc_with(self.xapian_id)
58
63
  end
59
64
  end
60
65
 
61
- # add the after destroy logic
62
- after :destroy do
63
- XapianDb.delete_doc_with(self.xapian_id)
64
- end
65
-
66
66
  # Add a method to reindex all models of this class
67
67
  define_singleton_method(:rebuild_xapian_index) do |options={}|
68
68
  options[:primary_key] = klass.serial.name
@@ -352,7 +352,7 @@ module XapianDb
352
352
  # @param [Array] args An array of arguments; you can pass a method name, an array of method names
353
353
  # or a method name and an options hash.
354
354
  # @param [Block] &block An optional block for complex configurations
355
- # Avaliable options:
355
+ # Available options:
356
356
  # - :weight (default: 1) The weight for this indexed value
357
357
  # @example Simple index declaration
358
358
  # blueprint.index :name
@@ -13,7 +13,7 @@ module XapianDb
13
13
  def index_task(options)
14
14
  klass = constantize options[:class]
15
15
  obj = klass.respond_to?(:get) ? klass.get(options[:id]) : klass.find(options[:id])
16
- DirectWriter.index obj, true, changed_attrs: options[:changed_attrs]
16
+ DirectWriter.index obj, options[:commit], changed_attrs: options[:changed_attrs]
17
17
  end
18
18
 
19
19
  def delete_doc_task(options)
@@ -19,7 +19,7 @@ module XapianDb
19
19
  # Update an object in the index
20
20
  # @param [Object] obj An instance of a class with a blueprint configuration
21
21
  def index(obj, commit=true, changed_attrs: [])
22
- beanstalk.put( { :task => "index_task", :class => obj.class.name, :id => obj.id, :changed_attrs => changed_attrs }.to_json )
22
+ beanstalk.put( { :task => "index_task", :class => obj.class.name, :id => obj.id, :changed_attrs => changed_attrs, :commit => commit }.to_json )
23
23
  end
24
24
 
25
25
  # Remove an object from the index
@@ -59,13 +59,16 @@ module XapianDb
59
59
  # Index all configured text methods
60
60
  def index_text
61
61
  term_generator = Xapian::TermGenerator.new
62
- term_generator.database = @database.writer
63
62
  term_generator.document = @xapian_doc
64
63
  if XapianDb::Config.stemmer
65
64
  term_generator.stemmer = XapianDb::Config.stemmer
66
65
  term_generator.stopper = XapianDb::Config.stopper if XapianDb::Config.stopper
67
66
  # Enable the creation of a spelling dictionary if the database is not in memory
68
- term_generator.set_flags Xapian::TermGenerator::FLAG_SPELLING if @database.is_a? XapianDb::PersistentDatabase
67
+ if @database.is_a?(XapianDb::PersistentDatabase) &&
68
+ XapianDb::Config.query_flags.include?(Xapian::QueryParser::FLAG_SPELLING_CORRECTION)
69
+ term_generator.database = @database.writer
70
+ term_generator.set_flags Xapian::TermGenerator::FLAG_SPELLING
71
+ end
69
72
  end
70
73
 
71
74
  # Index the primary key as a unique term
data/lib/xapian_db.rb CHANGED
@@ -106,21 +106,21 @@ module XapianDb
106
106
  # Update an object in the index
107
107
  # @param [Object] obj An instance of a class with a blueprint configuration
108
108
  def self.index(obj, commit=true, changed_attrs: [])
109
- writer = @block_writer || XapianDb::Config.writer
109
+ writer = Thread.current[:xapian_db_block_writer] || XapianDb::Config.writer
110
110
  writer.index obj, commit, changed_attrs: changed_attrs
111
111
  end
112
112
 
113
113
  # Remove a document from the index
114
114
  # @param [String] xapian_id The document id
115
115
  def self.delete_doc_with(xapian_id, commit=true)
116
- writer = @block_writer || XapianDb::Config.writer
116
+ writer = Thread.current[:xapian_db_block_writer] || XapianDb::Config.writer
117
117
  writer.delete_doc_with xapian_id, commit
118
118
  end
119
119
 
120
120
  # Update or delete a xapian document belonging to an object depending on the ignore_if logic(if present)
121
121
  # @param [Object] object An instance of a class with a blueprint configuration
122
122
  def self.reindex(object, commit=true, changed_attrs: [])
123
- writer = @block_writer || XapianDb::Config.writer
123
+ writer = Thread.current[:xapian_db_block_writer] || XapianDb::Config.writer
124
124
  blueprint = XapianDb::DocumentBlueprint.blueprint_for object.class.name
125
125
  if blueprint.should_index?(object)
126
126
  writer.index object, commit, changed_attrs: changed_attrs
@@ -174,7 +174,7 @@ module XapianDb
174
174
  # @option opts [Object] :writer An index writer
175
175
  # @option opts [String] :error_message the error message to log if an error occurs
176
176
  def self.execute_block(opts, &block)
177
- @block_writer = opts[:writer]
177
+ Thread.current[:xapian_db_block_writer] = opts[:writer]
178
178
  begin
179
179
  block.call
180
180
  rescue Exception => ex
@@ -188,7 +188,7 @@ module XapianDb
188
188
  raise
189
189
  ensure
190
190
  # release the block writer
191
- @block_writer = nil
191
+ Thread.current[:xapian_db_block_writer] = nil
192
192
  end
193
193
  end
194
194
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xapian_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.7.4
4
+ version: 1.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gernot Kogler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-27 00:00:00.000000000 Z
11
+ date: 2022-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daemons
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 1.2.22
145
+ version: 1.4.17
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: 1.2.22
152
+ version: 1.4.17
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: pry-rails
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -260,8 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
260
  - !ruby/object:Gem::Version
261
261
  version: 1.3.6
262
262
  requirements: []
263
- rubyforge_project:
264
- rubygems_version: 2.7.6
263
+ rubygems_version: 3.3.14
265
264
  signing_key:
266
265
  specification_version: 4
267
266
  summary: Ruby library to use a Xapian db as a key/value store with high performance