Changeset 5503f9


Ignore:
Timestamp:
05/09/2013 11:10:02 AM (12 years ago)
Author:
Calum Lind <calumlind+deluge@gmail.com>
Branches:
2.0.x, develop, master
Children:
daba92
Parents:
d5a385
git-author:
bendikro <bendikro@gmail.com> (02/21/2013 12:11:35 AM)
git-committer:
Calum Lind <calumlind+deluge@gmail.com> (05/09/2013 11:10:02 AM)
Message:

Fix #2285 : Speed optimizations for sessionproxy

Location:
deluge
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • deluge/tests/test_sessionproxy.py

    rd5a385 r5503f9  
    9090
    9191        def do_get_torrents_status(torrent_ids):
    92             inital_keys = [
    93                 'queue', 'state', 'name', 'total_wanted', 'progress', 'state',
    94                 'download_payload_rate', 'upload_payload_rate', 'eta', 'owner'
    95             ]
     92            inital_keys = ['key1']
    9693            self.sp.get_torrents_status({'id': torrent_ids}, inital_keys)
    9794        d.addCallback(do_get_torrents_status)
  • deluge/ui/sessionproxy.py

    rd5a385 r5503f9  
    100100        """
    101101        sd = {}
     102        keys = set(keys)
     103        keys_len = -1 # The number of keys for the current cache (not the len of keys_diff_cached)
     104        keys_diff_cached = []
     105
    102106        for torrent_id in torrent_ids:
    103107            try:
    104108                if keys:
    105                     sd[torrent_id] = dict([
    106                         (x, y) for x, y in self.torrents[torrent_id][1].iteritems()
    107                         if x in keys
    108                     ])
     109                    sd[torrent_id] = self.torrents[torrent_id][1].copy()
     110
     111                    # Have to remove the keys that weren't requested
     112                    if len(sd[torrent_id]) == keys_len:
     113                        # If the number of keys are equal they are the same keys
     114                        # so we use the cached diff of the keys we need to remove
     115                        keys_to_remove = keys_diff_cached
     116                    else:
     117                        # Not the same keys so create a new diff
     118                        keys_to_remove = set(sd[torrent_id].iterkeys()) - keys
     119                        # Update the cached diff
     120                        keys_diff_cached = keys_to_remove
     121                        keys_len = len(sd[torrent_id])
     122
     123                    # Usually there are no keys to remove, so it's cheaper with
     124                    # this if-test than a for-loop with no iterations.
     125                    if keys_to_remove:
     126                        for k in keys_to_remove:
     127                            del sd[torrent_id][k]
    109128                else:
    110129                    sd[torrent_id] = dict(self.torrents[torrent_id][1])
    111130            except KeyError:
    112131                continue
    113 
    114132        return sd
    115133
     
    185203            # Update the internal torrent status dict with the update values
    186204            t = time.time()
    187             for key, value in result.items():
     205            for key, value in result.iteritems():
    188206                try:
    189207                    self.torrents[key][0] = t
Note: See TracChangeset for help on using the changeset viewer.