Speed up annotations_count_for_book

No need to use a transaction for a single readonly operation
This commit is contained in:
Kovid Goyal 2020-11-02 09:22:33 +05:30
parent 3e53b5129b
commit 49e70ff532
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1949,10 +1949,9 @@ class DB(object):
return changed
def annotation_count_for_book(self, book_id):
with self.conn:
c = self.execute('SELECT count(id) FROM annotations WHERE book=?', (book_id,))
r = c.fetchone()[0]
return r
for (count,) in self.execute('SELECT count(id) FROM annotations WHERE book=?', (book_id,)):
return count
return 0
def conversion_options(self, book_id, fmt):
for (data,) in self.conn.get('SELECT data FROM conversion_options WHERE book=? AND format=?', (book_id, fmt.upper())):