diff options
author | Manuel QuiƱones <manuq@laptop.org> | 2013-09-04 19:37:13 (GMT) |
---|---|---|
committer | Manuel QuiƱones <manuq@laptop.org> | 2013-09-04 19:37:13 (GMT) |
commit | 3e9ea63e6db65636cf5609f6e68d4f00e4a7acf5 (patch) | |
tree | 800f2717172fb54b93ea17621f94f4ea3fa0be5e /downloadmanager.py | |
parent | 27d53fd7b2e62d6fb555ff8e669a92f0a299a354 (diff) |
Download: update progress only when the percent changes - #4619
Fixes #4619 . Too much calls to datastore.write() is ineffective.
Diffstat (limited to 'downloadmanager.py')
-rw-r--r-- | downloadmanager.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/downloadmanager.py b/downloadmanager.py index b2a4c35..02b5de0 100644 --- a/downloadmanager.py +++ b/downloadmanager.py @@ -97,16 +97,20 @@ class Download(object): self._download.start() def __progress_change_cb(self, download, something): - progress = self._download.get_progress() - self.dl_jobject.metadata['progress'] = str(int(progress * 100)) - datastore.write(self.dl_jobject) + progress = int(self._download.get_progress() * 100) + if progress > self._last_update_percent: + self._last_update_percent = progress + self.dl_jobject.metadata['progress'] = str(progress) + datastore.write(self.dl_jobject) def __current_size_changed_cb(self, download, something): current_size = self._download.get_current_size() total_size = self._download.get_total_size() - progress = current_size * 100 / total_size - self.dl_jobject.metadata['progress'] = str(progress) - datastore.write(self.dl_jobject) + progress = int(current_size * 100 / total_size) + if progress > self._last_update_percent: + self._last_update_percent = progress + self.dl_jobject.metadata['progress'] = str(progress) + datastore.write(self.dl_jobject) def __state_change_cb(self, download, gparamspec): state = self._download.get_status() |