diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index 404a2536fd..dadba92474 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -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']) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 96d3843b51..b43bd86c3b 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -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) diff --git a/src/calibre/db/tests/reading.py b/src/calibre/db/tests/reading.py index ded31f9546..c797d47f48 100644 --- a/src/calibre/db/tests/reading.py +++ b/src/calibre/db/tests/reading.py @@ -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'