Merge lp:~osomon/software-center/too_many_refreshes into lp:software-center

Proposed by Olivier Tilloy
Status: Merged
Merge reported by: Gary Lasker
Merged at revision: not available
Proposed branch: lp:~osomon/software-center/too_many_refreshes
Merge into: lp:software-center
Diff against target: 38 lines (+16/-1)
1 file modified
softwarecenter/apt/aptcache.py (+16/-1)
To merge this branch: bzr merge lp:~osomon/software-center/too_many_refreshes
Reviewer Review Type Date Requested Status
software-store-developers code functional Pending
Review via email: mp+23688@code.launchpad.net

Description of the change

This branch fixes bug #563163.

The APT cache's monitoring mechanism wasn't considering whether the cache had already been re-opened explicitly, and it was scheduling several re-openings in a row.

This branch introduces a timestamp for the cache to remember when it was last re-opened and discard notifications within an arbitrary period of 10 seconds after the last re-opening.

It also makes sure only one re-opening is scheduled at any given time at most.

To post a comment you must log in.
Revision history for this message
Gary Lasker (gary-lasker) wrote :

Hello Olivier!

I am going through open pending reviews and with regard to this one it seems not this exact branch, but a variant of your fix was committed to fix the corresponding bug 563163. Based on that (and the fact that the bug is set fix committed) I'll set the status of this review to merged.

Thanks as always for your good work! I'm sure you know it's very much appreciated.

Best to you! I look forward to talking to you soon,
Gary

Revision history for this message
Olivier Tilloy (osomon) wrote :

Hi Gary!
If I remember correctly, the branch Michael merged was a variation of mine that did the job too.
Thanks for the clean up. And we'll talk soon indeed :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'softwarecenter/apt/aptcache.py'
--- softwarecenter/apt/aptcache.py 2010-04-09 12:55:23 +0000
+++ softwarecenter/apt/aptcache.py 2010-04-19 18:18:16 +0000
@@ -67,6 +67,11 @@
67 self._ready = False67 self._ready = False
68 # async open cache68 # async open cache
69 glib.timeout_add(100, self.open)69 glib.timeout_add(100, self.open)
70 # Remember whether a call to re-open the cache is already pending
71 self._open_pending = False
72 # Remember when the cache was last re-opened, to avoid opening it too
73 # frequently.
74 self._last_opened = None
70 # setup monitor watch for install/remove changes75 # setup monitor watch for install/remove changes
71 self.apt_finished_stamp=gio.File(self.APT_FINISHED_STAMP)76 self.apt_finished_stamp=gio.File(self.APT_FINISHED_STAMP)
72 self.apt_finished_monitor = self.apt_finished_stamp.monitor_file(77 self.apt_finished_monitor = self.apt_finished_stamp.monitor_file(
@@ -74,11 +79,21 @@
74 self.apt_finished_monitor.connect(79 self.apt_finished_monitor.connect(
75 "changed", self._on_apt_finished_stamp_changed)80 "changed", self._on_apt_finished_stamp_changed)
76 def _on_apt_finished_stamp_changed(self, monitor, afile, other_file, event):81 def _on_apt_finished_stamp_changed(self, monitor, afile, other_file, event):
77 glib.timeout_add_seconds(10, self.open)82 if self._last_opened is not None and \
83 (time.time() - self._last_opened) < 10:
84 # The cache was already re-opened less than 10 seconds ago,
85 # probably on an explicit request (direct call to open()), ignore
86 # this notification.
87 return
88 if not self._open_pending:
89 self._open_pending = True
90 glib.timeout_add_seconds(10, self.open)
78 @property91 @property
79 def ready(self):92 def ready(self):
80 return self._ready93 return self._ready
81 def open(self):94 def open(self):
95 self._open_pending = False
96 self._last_opened = time.time()
82 self._ready = False97 self._ready = False
83 self.emit("cache-invalid")98 self.emit("cache-invalid")
84 if self._cache == None:99 if self._cache == None: