mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont show removed annotations in the browser
This commit is contained in:
parent
cf7a40a960
commit
0067cdd775
@ -1777,7 +1777,7 @@ class DB(object):
|
|||||||
|
|
||||||
def search_annotations(self,
|
def search_annotations(self,
|
||||||
fts_engine_query, use_stemming, highlight_start, highlight_end, snippet_size, annotation_type,
|
fts_engine_query, use_stemming, highlight_start, highlight_end, snippet_size, annotation_type,
|
||||||
restrict_to_book_ids, restrict_to_user
|
restrict_to_book_ids, restrict_to_user, ignore_removed=False
|
||||||
):
|
):
|
||||||
fts_table = 'annotations_fts_stemmed' if use_stemming else 'annotations_fts'
|
fts_table = 'annotations_fts_stemmed' if use_stemming else 'annotations_fts'
|
||||||
text = 'annotations.searchable_text'
|
text = 'annotations.searchable_text'
|
||||||
@ -1807,6 +1807,8 @@ class DB(object):
|
|||||||
parsed_annot = ls(annot_data)
|
parsed_annot = ls(annot_data)
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
if ignore_removed and parsed_annot.get('removed'):
|
||||||
|
continue
|
||||||
yield {
|
yield {
|
||||||
'id': rowid,
|
'id': rowid,
|
||||||
'book_id': book_id,
|
'book_id': book_id,
|
||||||
@ -1819,15 +1821,18 @@ class DB(object):
|
|||||||
except apsw.SQLError as e:
|
except apsw.SQLError as e:
|
||||||
raise FTSQueryError(fts_engine_query, query, e)
|
raise FTSQueryError(fts_engine_query, query, e)
|
||||||
|
|
||||||
def all_annotations_for_book(self, book_id):
|
def all_annotations_for_book(self, book_id, ignore_removed=False):
|
||||||
for (fmt, user_type, user, data) in self.execute('SELECT id, book, format, user_type, user, annot_data FROM annotations WHERE book=?', (book_id,)):
|
for (fmt, user_type, user, data) in self.execute(
|
||||||
|
'SELECT id, book, format, user_type, user, annot_data FROM annotations WHERE book=?', (book_id,)
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
yield {'format': fmt, 'user_type': user_type, 'user': user, 'annotation': json.loads(data)}
|
annot = json.loads(data)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
if not ignore_removed or not annot.get('removed'):
|
||||||
|
yield {'format': fmt, 'user_type': user_type, 'user': user, 'annotation': annot}
|
||||||
|
|
||||||
def all_annotations(self, restrict_to_user=None, limit=None, annotation_type=None):
|
def all_annotations(self, restrict_to_user=None, limit=None, annotation_type=None, ignore_removed=False):
|
||||||
ls = json.loads
|
ls = json.loads
|
||||||
q = 'SELECT id, book, format, user_type, user, annot_data FROM annotations'
|
q = 'SELECT id, book, format, user_type, user, annot_data FROM annotations'
|
||||||
data = []
|
data = []
|
||||||
@ -1840,14 +1845,15 @@ class DB(object):
|
|||||||
data.append(annotation_type)
|
data.append(annotation_type)
|
||||||
q += ' annot_type = ? '
|
q += ' annot_type = ? '
|
||||||
q += ' ORDER BY timestamp'
|
q += ' ORDER BY timestamp'
|
||||||
if limit is not None:
|
count = 0
|
||||||
q += ' LIMIT %d' % limit
|
|
||||||
for (rowid, book_id, fmt, user_type, user, annot_data) in self.execute(q, tuple(data)):
|
for (rowid, book_id, fmt, user_type, user, annot_data) in self.execute(q, tuple(data)):
|
||||||
try:
|
try:
|
||||||
annot = ls(annot_data)
|
annot = ls(annot_data)
|
||||||
atype = annot['type']
|
atype = annot['type']
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
if ignore_removed and annot.get('removed'):
|
||||||
|
continue
|
||||||
text = ''
|
text = ''
|
||||||
if atype == 'bookmark':
|
if atype == 'bookmark':
|
||||||
text = annot['title']
|
text = annot['title']
|
||||||
@ -1862,6 +1868,9 @@ class DB(object):
|
|||||||
'text': text,
|
'text': text,
|
||||||
'annotation': annot,
|
'annotation': annot,
|
||||||
}
|
}
|
||||||
|
count += 1
|
||||||
|
if limit is not None and count >= limit:
|
||||||
|
break
|
||||||
|
|
||||||
def all_annotation_users(self):
|
def all_annotation_users(self):
|
||||||
return self.execute('SELECT DISTINCT user_type, user FROM annotations')
|
return self.execute('SELECT DISTINCT user_type, user FROM annotations')
|
||||||
|
@ -2311,8 +2311,8 @@ class Cache(object):
|
|||||||
return tuple(self.backend.all_annotation_types())
|
return tuple(self.backend.all_annotation_types())
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def all_annotations(self, restrict_to_user=None, limit=None, annotation_type=None):
|
def all_annotations(self, restrict_to_user=None, limit=None, annotation_type=None, ignore_removed=False):
|
||||||
return tuple(self.backend.all_annotations(restrict_to_user, limit, annotation_type))
|
return tuple(self.backend.all_annotations(restrict_to_user, limit, annotation_type, ignore_removed))
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def search_annotations(
|
def search_annotations(
|
||||||
@ -2325,10 +2325,12 @@ class Cache(object):
|
|||||||
annotation_type=None,
|
annotation_type=None,
|
||||||
restrict_to_book_ids=None,
|
restrict_to_book_ids=None,
|
||||||
restrict_to_user=None,
|
restrict_to_user=None,
|
||||||
|
ignore_removed=False
|
||||||
):
|
):
|
||||||
return tuple(self.backend.search_annotations(
|
return tuple(self.backend.search_annotations(
|
||||||
fts_engine_query, use_stemming, highlight_start, highlight_end,
|
fts_engine_query, use_stemming, highlight_start, highlight_end,
|
||||||
snippet_size, annotation_type, restrict_to_book_ids, restrict_to_user
|
snippet_size, annotation_type, restrict_to_book_ids, restrict_to_user,
|
||||||
|
ignore_removed
|
||||||
))
|
))
|
||||||
|
|
||||||
@write_api
|
@write_api
|
||||||
|
@ -297,9 +297,15 @@ class BrowsePanel(QWidget):
|
|||||||
with BusyCursor():
|
with BusyCursor():
|
||||||
db = current_db()
|
db = current_db()
|
||||||
if not q['fts_engine_query']:
|
if not q['fts_engine_query']:
|
||||||
results = db.all_annotations(restrict_to_user=q['restrict_to_user'], limit=4096, annotation_type=q['annotation_type'])
|
results = db.all_annotations(
|
||||||
|
restrict_to_user=q['restrict_to_user'], limit=4096, annotation_type=q['annotation_type'],
|
||||||
|
ignore_removed=True
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
results = db.search_annotations(highlight_start='\x1d', highlight_end='\x1d', snippet_size=64, **q)
|
results = db.search_annotations(
|
||||||
|
highlight_start='\x1d', highlight_end='\x1d', snippet_size=64,
|
||||||
|
ignore_removed=True, **q
|
||||||
|
)
|
||||||
|
|
||||||
self.results_list.set_results(results, bool(q['fts_engine_query']))
|
self.results_list.set_results(results, bool(q['fts_engine_query']))
|
||||||
self.current_query = q
|
self.current_query = q
|
||||||
|
Loading…
x
Reference in New Issue
Block a user