Address comments

Reduce down to one counter variable.
Eliminate decrement at unqueue/increment at start request
Update counter emit aligned with counter increment/decrement.
This commit is contained in:
Sophist
2013-11-26 17:50:51 +00:00
parent 07839f8ca9
commit 7c4840083c
2 changed files with 4 additions and 7 deletions

View File

@@ -235,7 +235,7 @@ class MainWindow(QtGui.QMainWindow):
self.infostatus.setAlbums(len(self.tagger.albums))
self.infostatus.setPendingFiles(File.num_pending_files)
ws = self.tagger.xmlws
self.infostatus.setPendingRequests(ws.num_pending_web_requests + ws.num_active_requests)
self.infostatus.setPendingRequests(ws.num_pending_web_requests)
def update_statusbar_listen_port(self, listen_port):
if listen_port:

View File

@@ -145,7 +145,6 @@ class XmlWebService(QtCore.QObject):
"DELETE": self.manager.deleteResource
}
self.num_pending_web_requests = 0
self.num_active_requests = 0
def set_cache(self, cache_size_in_mb=100):
cache = QtNetwork.QNetworkDiskCache()
@@ -189,7 +188,6 @@ class XmlWebService(QtCore.QObject):
key = (host, port)
self._last_request_times[key] = time.time()
self._active_requests[reply] = (request, handler, xml)
self.num_active_requests += 1
return True
@staticmethod
@@ -203,7 +201,8 @@ class XmlWebService(QtCore.QObject):
leftUrl.toString(QUrl.RemovePort) == rightUrl.toString(QUrl.RemovePort)
def _process_reply(self, reply):
self.num_active_requests -= 1
self.num_pending_web_requests -= 1
self.tagger.tagger_stats_changed.emit()
try:
request, handler, xml = self._active_requests.pop(reply)
except KeyError:
@@ -297,13 +296,11 @@ class XmlWebService(QtCore.QObject):
log.debug("Last request to %s was %d ms ago, starting another one", key, last_ms)
d = request_delay
queue.popleft()()
self.num_pending_web_requests -= 1
else:
d = request_delay - last_ms
log.debug("Waiting %d ms before starting another request to %s", d, key)
if d < delay:
delay = d
self.tagger.tagger_stats_changed.emit()
if delay < sys.maxint:
self._timer.start(delay)
@@ -338,7 +335,7 @@ class XmlWebService(QtCore.QObject):
pass
else:
self.num_pending_web_requests -= 1
self.tagger.tagger_stats_changed.emit()
self.tagger.tagger_stats_changed.emit()
def _get_by_id(self, entitytype, entityid, handler, inc=[], params=[], priority=False, important=False, mblogin=False):
host = config.setting["server_host"]