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
1=== modified file 'softwarecenter/apt/aptcache.py'
2--- softwarecenter/apt/aptcache.py 2010-04-09 12:55:23 +0000
3+++ softwarecenter/apt/aptcache.py 2010-04-19 18:18:16 +0000
4@@ -67,6 +67,11 @@
5 self._ready = False
6 # async open cache
7 glib.timeout_add(100, self.open)
8+ # Remember whether a call to re-open the cache is already pending
9+ self._open_pending = False
10+ # Remember when the cache was last re-opened, to avoid opening it too
11+ # frequently.
12+ self._last_opened = None
13 # setup monitor watch for install/remove changes
14 self.apt_finished_stamp=gio.File(self.APT_FINISHED_STAMP)
15 self.apt_finished_monitor = self.apt_finished_stamp.monitor_file(
16@@ -74,11 +79,21 @@
17 self.apt_finished_monitor.connect(
18 "changed", self._on_apt_finished_stamp_changed)
19 def _on_apt_finished_stamp_changed(self, monitor, afile, other_file, event):
20- glib.timeout_add_seconds(10, self.open)
21+ if self._last_opened is not None and \
22+ (time.time() - self._last_opened) < 10:
23+ # The cache was already re-opened less than 10 seconds ago,
24+ # probably on an explicit request (direct call to open()), ignore
25+ # this notification.
26+ return
27+ if not self._open_pending:
28+ self._open_pending = True
29+ glib.timeout_add_seconds(10, self.open)
30 @property
31 def ready(self):
32 return self._ready
33 def open(self):
34+ self._open_pending = False
35+ self._last_opened = time.time()
36 self._ready = False
37 self.emit("cache-invalid")
38 if self._cache == None: