mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix performance problem when dropping books onto a user category
This commit is contained in:
parent
6bdbf29d6b
commit
fad1f2c74a
@ -685,44 +685,37 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
|
|
||||||
def handle_user_category_drop(self, on_node, ids, column):
|
def handle_user_category_drop(self, on_node, ids, column):
|
||||||
categories = self.db.prefs.get('user_categories', {})
|
categories = self.db.prefs.get('user_categories', {})
|
||||||
category = categories.get(on_node.category_key[1:], None)
|
cat_contents = categories.get(on_node.category_key[1:], None)
|
||||||
if category is None:
|
if cat_contents is None:
|
||||||
return
|
return
|
||||||
|
cat_contents = set([(v, c) for v,c,ign in cat_contents])
|
||||||
|
|
||||||
fm_src = self.db.metadata_for_field(column)
|
fm_src = self.db.metadata_for_field(column)
|
||||||
|
label = fm_src['label']
|
||||||
|
|
||||||
for id in ids:
|
for id in ids:
|
||||||
label = fm_src['label']
|
|
||||||
if not fm_src['is_custom']:
|
if not fm_src['is_custom']:
|
||||||
if label == 'authors':
|
if label == 'authors':
|
||||||
items = self.db.get_authors_with_ids()
|
|
||||||
items = [(i[0], i[1].replace('|', ',')) for i in items]
|
|
||||||
value = self.db.authors(id, index_is_id=True)
|
value = self.db.authors(id, index_is_id=True)
|
||||||
value = [v.replace('|', ',') for v in value.split(',')]
|
value = [v.replace('|', ',') for v in value.split(',')]
|
||||||
elif label == 'publisher':
|
elif label == 'publisher':
|
||||||
items = self.db.get_publishers_with_ids()
|
|
||||||
value = self.db.publisher(id, index_is_id=True)
|
value = self.db.publisher(id, index_is_id=True)
|
||||||
elif label == 'series':
|
elif label == 'series':
|
||||||
items = self.db.get_series_with_ids()
|
|
||||||
value = self.db.series(id, index_is_id=True)
|
value = self.db.series(id, index_is_id=True)
|
||||||
else:
|
else:
|
||||||
items = self.db.get_custom_items_with_ids(label=label)
|
|
||||||
if fm_src['datatype'] != 'composite':
|
if fm_src['datatype'] != 'composite':
|
||||||
value = self.db.get_custom(id, label=label, index_is_id=True)
|
value = self.db.get_custom(id, label=label, index_is_id=True)
|
||||||
else:
|
else:
|
||||||
value = self.db.get_property(id, loc=fm_src['rec_index'],
|
value = self.db.get_property(id, loc=fm_src['rec_index'],
|
||||||
index_is_id=True)
|
index_is_id=True)
|
||||||
if value is None:
|
if value:
|
||||||
return
|
if not isinstance(value, list):
|
||||||
if not isinstance(value, list):
|
value = [value]
|
||||||
value = [value]
|
cat_contents |= set([(v, column) for v in value])
|
||||||
for val in value:
|
|
||||||
for (v, c, id) in category:
|
categories[on_node.category_key[1:]] = [[v, c, 0] for v,c in cat_contents]
|
||||||
if v == val and c == column:
|
self.db.prefs.set('user_categories', categories)
|
||||||
break
|
self.refresh_required.emit()
|
||||||
else:
|
|
||||||
category.append([val, column, 0])
|
|
||||||
categories[on_node.category_key[1:]] = category
|
|
||||||
self.db.prefs.set('user_categories', categories)
|
|
||||||
self.refresh_required.emit()
|
|
||||||
|
|
||||||
def handle_drop(self, on_node, ids):
|
def handle_drop(self, on_node, ids):
|
||||||
#print 'Dropped ids:', ids, on_node.tag
|
#print 'Dropped ids:', ids, on_node.tag
|
||||||
|
Loading…
x
Reference in New Issue
Block a user