full_search 0.4.6 → 0.4.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffdca4041a68a79686da2b8d636b3feadb88d39fd6ca2ff8f3c6ec955d52355c
4
- data.tar.gz: 8438b904a538c0d8c8e0250bf751209b44f8a095aacfc1089cb180a5cbb21d8f
3
+ metadata.gz: a47cd95db7244715db988cdce15e8466dc2131d3a995769071ca7b513f7b91e4
4
+ data.tar.gz: 35303e2f06de22ccfcd1e20018d8f1a83cd1d32bd2d883cdd7ba60c1919d3541
5
5
  SHA512:
6
- metadata.gz: 447a5e7b51909e3098a38439935facf534ad7a97c84eb399af7fbd5e844c966787ac74651a58993000d12b0c18d3a6851fe3ea1e32b854629ff97b5c9e1906a0
7
- data.tar.gz: d43d646f9e95ad6bc8d4425c8601b9c5f2695f106965cba1b53881cf8e155581a3421055f1b6babc0468aaf0a02c589e1e615f95dfecb42cd776adebae320bb5
6
+ metadata.gz: 1316924b824ef6814d2899ee165426b8eee7b021fc7bde0ee358f6a9066f2668561f27fb1de12f12bd0d3b836f91a2d428eb1c9da9e0db7dc494cf037ea707e5
7
+ data.tar.gz: 3c359e74e2898302ef51ada7f864c22c1b2dd340fb27e5e097b59baa78bae97b800d74ad020f172f202c2da85d3094925aba3fbad9cdc00dc5929fd990803dab
@@ -167,8 +167,8 @@ module FullSearch
167
167
 
168
168
  conn = connection
169
169
  begin
170
- conn.execute("DELETE FROM #{qt(fts_table_name(model))};")
171
- conn.execute("DELETE FROM #{qt(trigram_table_name(model))};") if trigram_table_needed?(model) && trigram_table_exists?(model)
170
+ with_busy_retry { conn.execute("DELETE FROM #{qt(fts_table_name(model))};") }
171
+ with_busy_retry { conn.execute("DELETE FROM #{qt(trigram_table_name(model))};") } if trigram_table_needed?(model) && trigram_table_exists?(model)
172
172
  rescue ActiveRecord::StatementInvalid => e
173
173
  raise unless e.message.match?(/fts5: corruption|invalid fts5 file format|malformed database schema/i)
174
174
 
@@ -191,12 +191,12 @@ module FullSearch
191
191
  # drop the shadow tables directly, then drop the (now-empty) virtual
192
192
  # table wrapper, so the caller can recreate a clean index.
193
193
  def drop_fts_table_safely!(table_name)
194
- connection.execute("DROP TABLE IF EXISTS #{qt(table_name)};")
194
+ with_busy_retry { connection.execute("DROP TABLE IF EXISTS #{qt(table_name)};") }
195
195
  rescue ActiveRecord::StatementInvalid => e
196
196
  raise unless e.message.match?(/fts5: corruption|invalid fts5 file format|malformed database schema/i)
197
197
 
198
198
  drop_shadow_tables!(table_name)
199
- connection.execute("DROP TABLE IF EXISTS #{qt(table_name)};")
199
+ with_busy_retry { connection.execute("DROP TABLE IF EXISTS #{qt(table_name)};") }
200
200
  end
201
201
 
202
202
  # FTS5 stores its index data in a fixed set of shadow tables named
@@ -249,12 +249,14 @@ module FullSearch
249
249
  def healthy?(model)
250
250
  return false unless table_exists?(model)
251
251
 
252
- connection.execute("SELECT count(*) FROM #{qt(fts_table_name(model))}")
253
- true
254
- rescue ActiveRecord::StatementInvalid => e
255
- raise unless e.message.match?(/fts5: corruption|invalid fts5 file format|malformed database schema/i)
252
+ begin
253
+ with_busy_retry { connection.execute("SELECT count(*) FROM #{qt(fts_table_name(model))}") }
254
+ true
255
+ rescue ActiveRecord::StatementInvalid => e
256
+ raise unless e.message.match?(/fts5: corruption|invalid fts5 file format|malformed database schema/i)
256
257
 
257
- false
258
+ false
259
+ end
258
260
  end
259
261
 
260
262
  def trigram_table_needed?(model)
@@ -285,6 +287,22 @@ module FullSearch
285
287
 
286
288
  private
287
289
 
290
+ BUSY_RETRIES = 3
291
+ BUSY_BACKOFF = 0.1
292
+
293
+ def with_busy_retry
294
+ attempts = 0
295
+ begin
296
+ yield
297
+ rescue ActiveRecord::StatementInvalid => e
298
+ raise unless e.message.match?(/database is locked/i) && attempts < BUSY_RETRIES
299
+ attempts += 1
300
+ sleep(BUSY_BACKOFF * attempts)
301
+ IndexCache.clear!
302
+ retry
303
+ end
304
+ end
305
+
288
306
  def connection
289
307
  ActiveRecord::Base.connection
290
308
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FullSearch
4
- VERSION = "0.4.6"
4
+ VERSION = "0.4.7"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: full_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben D'Angelo
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  - !ruby/object:Gem::Version
190
190
  version: '2.0'
191
191
  requirements: []
192
- rubygems_version: 4.0.15
192
+ rubygems_version: 4.0.10
193
193
  specification_version: 4
194
194
  summary: SQLite FTS5 full-text search for Rails/ActiveRecord
195
195
  test_files: []