mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-18 14:26:24 +00:00
Fix the sessionproxy when using keyworded filters.
The caching of state filters has been removed to simplify things a bit. This shouldn't have too much impact since the torrent status requests are still using diffs.
This commit is contained in:
parent
5dab17df89
commit
117fe3bb43
@ -62,10 +62,6 @@ class SessionProxy(component.Component):
|
|||||||
# Hold the torrents' status.. {torrent_id: [time, {status_dict}], ...}
|
# Hold the torrents' status.. {torrent_id: [time, {status_dict}], ...}
|
||||||
self.torrents = {}
|
self.torrents = {}
|
||||||
|
|
||||||
# Hold the time awhen the last state filter was used and the torrent_ids returned
|
|
||||||
# [(filter_dict, time, (torrent_id, ...)), ...]
|
|
||||||
self.state_filter_queries = []
|
|
||||||
|
|
||||||
client.register_event_handler("TorrentStateChangedEvent", self.on_torrent_state_changed)
|
client.register_event_handler("TorrentStateChangedEvent", self.on_torrent_state_changed)
|
||||||
client.register_event_handler("TorrentRemovedEvent", self.on_torrent_removed)
|
client.register_event_handler("TorrentRemovedEvent", self.on_torrent_removed)
|
||||||
client.register_event_handler("TorrentAddedEvent", self.on_torrent_added)
|
client.register_event_handler("TorrentAddedEvent", self.on_torrent_added)
|
||||||
@ -81,13 +77,6 @@ class SessionProxy(component.Component):
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.torrents = {}
|
self.torrents = {}
|
||||||
self.state_filter_queries = {}
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
# Clean-up any stale filter queries
|
|
||||||
sfq = self.state_filter_queries
|
|
||||||
t = time.time()
|
|
||||||
self.state_filter_queries = [x for x in sfq if (t - x[1]) < self.cache_time]
|
|
||||||
|
|
||||||
def create_status_dict(self, torrent_ids, keys):
|
def create_status_dict(self, torrent_ids, keys):
|
||||||
"""
|
"""
|
||||||
@ -165,7 +154,7 @@ class SessionProxy(component.Component):
|
|||||||
|
|
||||||
# Create the status dict
|
# Create the status dict
|
||||||
if not torrent_ids:
|
if not torrent_ids:
|
||||||
torrent_ids = self.torrents.keys()
|
torrent_ids = result.keys()
|
||||||
|
|
||||||
return self.create_status_dict(torrent_ids, keys)
|
return self.create_status_dict(torrent_ids, keys)
|
||||||
|
|
||||||
@ -186,40 +175,26 @@ class SessionProxy(component.Component):
|
|||||||
to_fetch = find_torrents_to_fetch(self.torrents.keys())
|
to_fetch = find_torrents_to_fetch(self.torrents.keys())
|
||||||
if to_fetch:
|
if to_fetch:
|
||||||
d = client.core.get_torrents_status({"id": to_fetch}, keys, True)
|
d = client.core.get_torrents_status({"id": to_fetch}, keys, True)
|
||||||
return d.addCallback(on_status, [], keys)
|
return d.addCallback(on_status, self.torrents.keys(), keys)
|
||||||
|
|
||||||
# Don't need to fetch anything
|
# Don't need to fetch anything
|
||||||
return maybeDeferred(self.create_status_dict, self.torrents.keys(), keys)
|
return maybeDeferred(self.create_status_dict, self.torrents.keys(), keys)
|
||||||
|
|
||||||
if "state" in filter_dict:
|
|
||||||
# We check if a similar query has already been done within our cache time
|
|
||||||
# and return results for those torrent_ids
|
|
||||||
for sfq in self.state_filter_queries:
|
|
||||||
if sfq[0] == filter_dict and (time.time() - sfq[1]) < self.cache_time:
|
|
||||||
# We found a winner!
|
|
||||||
if "id" in filter_dict:
|
|
||||||
filter_fict["id"].extend(sfq[2])
|
|
||||||
else:
|
|
||||||
filter_dict["id"] = sfq[2]
|
|
||||||
del filter_dict["state"]
|
|
||||||
break
|
|
||||||
|
|
||||||
if "state" in filter_dict:
|
if len(filter_dict) == 1 and "id" in filter_dict:
|
||||||
# If we got there, then there is no suitable cached filter query, so
|
# At this point we should have a filter with just "id" in it
|
||||||
# we'll just query the core
|
to_fetch = find_torrents_to_fetch(filter_dict["id"])
|
||||||
d = client.core.get_torrents_status(filter_dict, keys, True)
|
if to_fetch:
|
||||||
def on_filter_status(result, keys):
|
d = client.core.get_torrents_status({"id": to_fetch}, keys, True)
|
||||||
return on_status(result, result.keys(), keys)
|
return d.addCallback(on_status, filter_dict["id"], keys)
|
||||||
return d.addCallback(on_filter_status, keys)
|
else:
|
||||||
|
# Don't need to fetch anything, so just return data from the cache
|
||||||
# At this point we should have a filter with just "id" in it
|
return maybeDeferred(self.create_status_dict, filter_dict["id"], keys)
|
||||||
to_fetch = find_torrents_to_fetch(filter_dict["id"])
|
|
||||||
if to_fetch:
|
|
||||||
d = client.core.get_torrents_status({"id": to_fetch}, keys, True)
|
|
||||||
return d.addCallback(on_status, filter_dict["id"], keys)
|
|
||||||
else:
|
else:
|
||||||
# Don't need to fetch anything, so just return data from the cache
|
# This is a keyworded filter so lets just pass it onto the core
|
||||||
return maybeDeferred(self.create_status_dict, filter_dict["id"], keys)
|
# XXX: Add more caching here.
|
||||||
|
d = client.core.get_torrents_status(filter_dict, keys, True)
|
||||||
|
return d.addCallback(on_status, None, keys)
|
||||||
|
|
||||||
def on_torrent_state_changed(self, torrent_id, state):
|
def on_torrent_state_changed(self, torrent_id, state):
|
||||||
self.torrents[torrent_id][1]["state"] = state
|
self.torrents[torrent_id][1]["state"] = state
|
||||||
|
Loading…
x
Reference in New Issue
Block a user