mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont read the full notes table every time book details is rendered
Instead check if our particular items have notes only. This is a bit more work when no notes are present but is much less work when a significant number of notes are present.
This commit is contained in:
parent
f099932882
commit
2a9e0209ed
@ -109,7 +109,7 @@ def mi_to_html(
|
||||
mi,
|
||||
field_list=None, default_author_link=None, use_roman_numbers=True,
|
||||
rating_font='Liberation Serif', rtl=False, comments_heading_pos='hide',
|
||||
for_qt=False, vertical_fields=(), show_links=True, all_notes=None
|
||||
for_qt=False, vertical_fields=(), show_links=True, item_id_if_has_note=None
|
||||
):
|
||||
|
||||
link_markup = '↗️'
|
||||
@ -130,13 +130,11 @@ def mi_to_html(
|
||||
link = ' <a title="{0}: {1}" href="{1}">{2}</a>'.format(_('Click to open'), link, link_markup)
|
||||
else:
|
||||
link = ''
|
||||
if field_value in all_notes.get(field, set()):
|
||||
note = ' <a title="{0}" href="{1}">{2}</a>'.format(_('Click to open note'),
|
||||
notes_action(field=field, value=field_value,
|
||||
item_id=all_notes.get(field).get(field_value)),
|
||||
note_markup)
|
||||
else:
|
||||
note = ''
|
||||
note = ''
|
||||
item_id = None if item_id_if_has_note is None else item_id_if_has_note(field, field_value)
|
||||
if item_id is not None:
|
||||
note = ' <a title="{0}" href="{1}">{2}</a>'.format(
|
||||
_('Click to open note'), notes_action(field=field, value=field_value, item_id=item_id), note_markup)
|
||||
return link + note
|
||||
return ''
|
||||
|
||||
|
@ -322,13 +322,19 @@ def render_data(mi, use_roman_numbers=True, all_fields=False, pref_name='book_di
|
||||
field_list = [(x, all_fields or display) for x, display in field_list]
|
||||
db, _ = db_for_mi(mi)
|
||||
db = db.new_api
|
||||
an = db.get_all_items_that_have_notes()
|
||||
all_notes = {fld: {db.get_item_name(fld, id_):id_ for id_ in an[fld]} for fld in an.keys()}
|
||||
|
||||
def item_id_if_has_note(field, item_val):
|
||||
if db.field_supports_notes(field):
|
||||
item_id = db.get_item_id(field, item_val)
|
||||
if item_id is not None:
|
||||
if db.notes_for(field, item_id):
|
||||
return item_id
|
||||
|
||||
return mi_to_html(
|
||||
mi, field_list=field_list, use_roman_numbers=use_roman_numbers, rtl=is_rtl(),
|
||||
rating_font=rating_font(), default_author_link=default_author_link(),
|
||||
comments_heading_pos=gprefs['book_details_comments_heading_pos'], for_qt=True,
|
||||
vertical_fields=vertical_fields, show_links=show_links, all_notes=all_notes
|
||||
vertical_fields=vertical_fields, show_links=show_links, item_id_if_has_note=item_id_if_has_note
|
||||
)
|
||||
|
||||
# }}}
|
||||
|
@ -450,11 +450,6 @@ class TagBrowserMixin: # {{{
|
||||
d = EnumValuesEdit(parent, db, key)
|
||||
d.exec()
|
||||
|
||||
def do_tag_item_renamed(self):
|
||||
# The method name was changed. Keep the old one here for compatibility,
|
||||
# in case some plugin uses it.
|
||||
self.do_field_item_value_changed()
|
||||
|
||||
def do_field_item_value_changed(self):
|
||||
# Clean up library view and search, which also cleans up book details
|
||||
|
||||
@ -468,6 +463,7 @@ class TagBrowserMixin: # {{{
|
||||
m.research()
|
||||
self.library_view.select_rows(ids)
|
||||
# refreshing the tags view happens at the emit()/call() site
|
||||
do_tag_item_renamed = do_field_item_value_changed # alias for backcompat
|
||||
|
||||
def do_author_sort_edit(self, parent, id_, select_sort=True,
|
||||
select_link=False, is_first_letter=False,
|
||||
|
Loading…
x
Reference in New Issue
Block a user