Use the actual max number of variable supported by the sqlite connection

This commit is contained in:
Kovid Goyal 2025-12-19 15:38:30 +05:30
parent 12b4b50969
commit 6776f6c05d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 7 additions and 2 deletions

View File

@ -554,6 +554,10 @@ class DB:
set_global_state(self)
self.initialize_notes()
@property
def max_number_of_variables(self) -> int:
return self.conn.limit(apsw.SQLITE_LIMIT_VARIABLE_NUMBER)
@property
def last_expired_trash_at(self) -> float:
return float(self.prefs['last_expired_trash_at'])

View File

@ -918,7 +918,7 @@ class Cache:
books_by_year[year].add(book_id)
else:
books = tuple(restrict_to_books)
BATCH_SIZE = 900
BATCH_SIZE = self.backend.max_number_of_variables
for i in range(0, len(books), BATCH_SIZE):
batch = books[i:i + BATCH_SIZE]
placeholders = '?,' * len(batch)
@ -943,7 +943,7 @@ class Cache:
ans[(year, month)].add(book_id)
else:
books = tuple(restrict_to_books)
BATCH_SIZE = 900
BATCH_SIZE = self.backend.max_number_of_variables
for i in range(0, len(books), BATCH_SIZE):
batch = books[i:i + BATCH_SIZE]
placeholders = '?,' * len(batch)

View File

@ -472,6 +472,7 @@ class ReadingTest(BaseTest):
self.assertEqual(cache.books_by_year(restrict_to_books={1,2}), {2011: {1, 2}})
self.assertEqual(cache.books_by_month(), {(2011, 8): {1}, (2011, 9): {2, 3}})
self.assertEqual(cache.books_by_month(restrict_to_books={1,2}), {(2011, 8): {1}, (2011, 9): {2}})
self.assertEqual(cache.books_by_year(restrict_to_books=range(cache.backend.max_number_of_variables+200)), {2011: {1, 2, 3}})
def test_author_sort_for_authors(self): # {{{
'Test getting the author sort for authors from the db'