Cache items in get_filter_tree

This commit is contained in:
bendikro 2013-05-25 01:08:32 +02:00 committed by Calum Lind
parent 899c575ae8
commit affe47a11c
1 changed files with 8 additions and 1 deletions

View File

@ -34,6 +34,7 @@
#
import logging
import copy
import deluge.component as component
STATE_SORT = ["All", "Downloading", "Seeding", "Active", "Paused", "Queued"]
@ -130,6 +131,8 @@ class FilterManager(component.Component):
self.register_filter("keyword", filter_keywords)
self.register_filter("name", filter_by_name)
self.tree_fields = {}
self.prev_filter_tree_keys = None
self.filter_tree_items = None
self.register_tree_field("state", self._init_state_tree)
def _init_tracker_tree():
@ -211,7 +214,11 @@ class FilterManager(component.Component):
tree_keys.remove(cat)
torrent_keys, plugin_keys = self.torrents.separate_keys(tree_keys, torrent_ids)
items = dict((field, self.tree_fields[field]()) for field in tree_keys)
# Keys are the same, so use previous items
if self.prev_filter_tree_keys != tree_keys:
self.filter_tree_items = dict((field, self.tree_fields[field]()) for field in tree_keys)
self.prev_filter_tree_keys = tree_keys
items = copy.deepcopy(self.filter_tree_items)
for torrent_id in list(torrent_ids):
status = self.core.create_torrent_status(torrent_id, torrent_keys, plugin_keys) #status={key:value}