full_search 0.4.3 → 0.4.4
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 +4 -4
- data/lib/full_search/index.rb +28 -4
- data/lib/full_search/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 99b631f72162065698bc187ad0b88cb7602cbead185b5c82209db713774e763d
|
|
4
|
+
data.tar.gz: 5e1dd5a0782e69cba81b0b2c8f32170046f4c0e3ad55debb063837117285a559
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 146763f433fba78ed55b6a638b1d8a80bed0ea886daf294ff8e9389d09efef104b7ae6729d8897ee3ea267a4d38cf5d9956e691f4524da4a0861df6827c909ba
|
|
7
|
+
data.tar.gz: 65c5e59005e1730e12fadda9126b397a5fffdef462bcda088e7f14259b3635d1df7356d91dd23ebb312e6403489bf461b6088fc29a68b86b38fdbb80c4786ac2
|
data/lib/full_search/index.rb
CHANGED
|
@@ -71,8 +71,8 @@ module FullSearch
|
|
|
71
71
|
with_rebuild_lock(model) do
|
|
72
72
|
FullSearch::Instrumentation.instrument("rebuild", model: model.name) do
|
|
73
73
|
drop_triggers!(model)
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
drop_fts_table_safely!(fts_table_name(model))
|
|
75
|
+
drop_fts_table_safely!(trigram_table_name(model))
|
|
76
76
|
conn.execute(create_virtual_table_sql(model))
|
|
77
77
|
if trigram_table_needed?(model)
|
|
78
78
|
FullSearch::Typo.warn_unsupported!(model) unless FullSearch::Typo.supported?(model)
|
|
@@ -181,8 +181,32 @@ module FullSearch
|
|
|
181
181
|
verified_tables.delete(model.table_name)
|
|
182
182
|
sqlite!(model)
|
|
183
183
|
drop_triggers!(model)
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
drop_fts_table_safely!(fts_table_name(model))
|
|
185
|
+
drop_fts_table_safely!(trigram_table_name(model))
|
|
186
|
+
end
|
|
187
|
+
# Drops an FTS5 virtual table, recovering from corruption where a bare
|
|
188
|
+
# DROP TABLE IF EXISTS raises "invalid fts5 file format" because the
|
|
189
|
+
# shadow tables were tampered with out-of-band. When that happens we
|
|
190
|
+
# drop the shadow tables directly, then drop the (now-empty) virtual
|
|
191
|
+
# table wrapper, so the caller can recreate a clean index.
|
|
192
|
+
def drop_fts_table_safely!(table_name)
|
|
193
|
+
connection.execute("DROP TABLE IF EXISTS #{qt(table_name)};")
|
|
194
|
+
rescue ActiveRecord::StatementInvalid => e
|
|
195
|
+
raise unless e.message.match?(/fts5: corruption|invalid fts5 file format|malformed database schema/i)
|
|
196
|
+
|
|
197
|
+
drop_shadow_tables!(table_name)
|
|
198
|
+
connection.execute("DROP TABLE IF EXISTS #{qt(table_name)};")
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# FTS5 stores its index data in a fixed set of shadow tables named
|
|
202
|
+
# <table>_content, <table>_data, <table>_idx, <table>_docsize and
|
|
203
|
+
# <table>_config. Dropping these lets SQLite recover a virtual table
|
|
204
|
+
# that is otherwise undroppable due to internal corruption.
|
|
205
|
+
def drop_shadow_tables!(table_name)
|
|
206
|
+
%w[content data idx docsize config].each do |suffix|
|
|
207
|
+
shadow = "#{table_name}_#{suffix}"
|
|
208
|
+
connection.execute("DROP TABLE IF EXISTS #{qt(shadow)};")
|
|
209
|
+
end
|
|
186
210
|
end
|
|
187
211
|
|
|
188
212
|
def fts_table_name(model)
|
data/lib/full_search/version.rb
CHANGED