mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Add more fts indexing tests
This commit is contained in:
parent
d009e10942
commit
81a0f1b386
@ -16,6 +16,7 @@ import shutil
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
from contextlib import suppress
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from calibre import as_unicode, force_unicode, isbytestring, prints
|
from calibre import as_unicode, force_unicode, isbytestring, prints
|
||||||
@ -377,10 +378,23 @@ class Connection(apsw.Connection): # {{{
|
|||||||
ans = self.cursor().execute(*args)
|
ans = self.cursor().execute(*args)
|
||||||
if kw.get('all', True):
|
if kw.get('all', True):
|
||||||
return ans.fetchall()
|
return ans.fetchall()
|
||||||
try:
|
with suppress(StopIteration, IndexError):
|
||||||
return next(ans)[0]
|
return next(ans)[0]
|
||||||
except (StopIteration, IndexError):
|
|
||||||
return None
|
def get_dict(self, *args, all=True):
|
||||||
|
ans = self.cursor().execute(*args)
|
||||||
|
desc = ans.getdescription()
|
||||||
|
field_names = tuple(x[0] for x in desc)
|
||||||
|
|
||||||
|
def as_dict(row):
|
||||||
|
return dict(zip(field_names, row))
|
||||||
|
|
||||||
|
if all:
|
||||||
|
return tuple(map(as_dict, ans))
|
||||||
|
ans = ans.fetchone()
|
||||||
|
if ans is not None:
|
||||||
|
ans = as_dict(ans)
|
||||||
|
return ans
|
||||||
|
|
||||||
def execute(self, sql, bindings=None):
|
def execute(self, sql, bindings=None):
|
||||||
cursor = self.cursor()
|
cursor = self.cursor()
|
||||||
|
@ -62,12 +62,13 @@ class Worker(Thread):
|
|||||||
self.working = True
|
self.working = True
|
||||||
try:
|
try:
|
||||||
res = self.run_job(x)
|
res = self.run_job(x)
|
||||||
if res is not None:
|
if res is not None and self.keep_going:
|
||||||
self.supervise_queue.put(res)
|
self.supervise_queue.put(res)
|
||||||
except Exception:
|
except Exception:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
self.supervise_queue.put(Result(x, tb))
|
if self.keep_going:
|
||||||
|
self.supervise_queue.put(Result(x, tb))
|
||||||
finally:
|
finally:
|
||||||
self.working = False
|
self.working = False
|
||||||
|
|
||||||
|
@ -35,6 +35,9 @@ class FTSAPITest(BaseTest):
|
|||||||
while fts.all_currently_dirty() and time.monotonic() - st < timeout:
|
while fts.all_currently_dirty() and time.monotonic() - st < timeout:
|
||||||
fts.pool.supervisor_thread.join(0.01)
|
fts.pool.supervisor_thread.join(0.01)
|
||||||
|
|
||||||
|
def text_records(self, fts):
|
||||||
|
return fts.get_connection().get_dict('SELECT * FROM fts_db.books_text')
|
||||||
|
|
||||||
def test_fts_pool(self):
|
def test_fts_pool(self):
|
||||||
cache = self.init_cache()
|
cache = self.init_cache()
|
||||||
fts = cache.enable_fts()
|
fts = cache.enable_fts()
|
||||||
@ -43,6 +46,24 @@ class FTSAPITest(BaseTest):
|
|||||||
cache.add_format(1, 'TXT', BytesIO(b'a test text'))
|
cache.add_format(1, 'TXT', BytesIO(b'a test text'))
|
||||||
self.wait_for_fts_to_finish(fts)
|
self.wait_for_fts_to_finish(fts)
|
||||||
|
|
||||||
|
def q(rec, **kw):
|
||||||
|
self.ae({x: rec[x] for x in kw}, kw)
|
||||||
|
|
||||||
|
def check(**kw):
|
||||||
|
tr = self.text_records(fts)
|
||||||
|
self.ae(len(tr), 1)
|
||||||
|
q(tr[0], **kw)
|
||||||
|
|
||||||
|
check(id=1, book=1, format='TXT', searchable_text='a test text')
|
||||||
|
# check re-adding does not rescan
|
||||||
|
cache.add_format(1, 'TXT', BytesIO(b'a test text'))
|
||||||
|
self.wait_for_fts_to_finish(fts)
|
||||||
|
check(id=1, book=1, format='TXT', searchable_text='a test text')
|
||||||
|
# check updating rescans
|
||||||
|
cache.add_format(1, 'TXT', BytesIO(b'a test text2'))
|
||||||
|
self.wait_for_fts_to_finish(fts)
|
||||||
|
check(id=2, book=1, format='TXT', searchable_text='a test text2')
|
||||||
|
|
||||||
def test_fts_triggers(self):
|
def test_fts_triggers(self):
|
||||||
cache = self.init_cache()
|
cache = self.init_cache()
|
||||||
fts = cache.enable_fts(start_pool=False)
|
fts = cache.enable_fts(start_pool=False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user