[gnome-music/gnome-3-16] Backport rate-limiting patches from master
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/gnome-3-16] Backport rate-limiting patches from master
- Date: Wed, 17 Jun 2015 10:46:01 +0000 (UTC)
commit 76460e40d117005395ae32d749f8a11994881b9d
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date: Tue Jun 16 17:22:13 2015 +0200
Backport rate-limiting patches from master
grilo: rate-limit content-changed signal
window: rate-limit store_window_size_and_position
gnomemusic/__init__.py | 21 +++++++++++++++++++++
gnomemusic/grilo.py | 3 ++-
gnomemusic/window.py | 3 ++-
3 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/__init__.py b/gnomemusic/__init__.py
index a69b937..aa83295 100644
--- a/gnomemusic/__init__.py
+++ b/gnomemusic/__init__.py
@@ -28,6 +28,7 @@
from gi.repository import Tracker
from itertools import chain
import logging
+import time
logger = logging.getLogger(__name__)
tabbing = 0
@@ -52,6 +53,26 @@ def log(fn):
return wrapped
+def RateLimited(maxPerSecond):
+ minInterval = 1.0 / float(maxPerSecond)
+
+ def decorate(func):
+ lastTimeCalled = [0.0]
+
+ def rateLimitedFunction(*args, **kargs):
+ elapsed = time.clock() - lastTimeCalled[0]
+ leftToWait = minInterval - elapsed
+ if leftToWait > 0:
+ time.sleep(leftToWait)
+ ret = func(*args, **kargs)
+ lastTimeCalled[0] = time.clock()
+ return ret
+
+ return rateLimitedFunction
+
+ return decorate
+
+
class TrackerWrapper:
class __TrackerWrapper:
def __init__(self):
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 2da0e04..dac1ab6 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -26,7 +26,7 @@
# delete this exception statement from your version.
from gi.repository import GLib, GObject
from gnomemusic.query import Query
-from gnomemusic import log, TrackerWrapper
+from gnomemusic import log, RateLimited, TrackerWrapper
import logging
import os
os.environ['GRL_PLUGIN_RANKS'] = 'local-metadata:3,filesystem:2,tracker:1,lastfm-albumart:0'
@@ -98,6 +98,7 @@ class Grilo(GObject.GObject):
logger.debug("tracker found")
@log
+ @RateLimited(2)
def _on_content_changed(self, mediaSource, changedMedias, changeType, locationUnknown):
try:
with self.tracker.handler_block(self.notification_handler):
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index ef7c2b5..3f66cf1 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -42,7 +42,7 @@ import gnomemusic.view as Views
import gnomemusic.widgets as Widgets
from gnomemusic.playlists import Playlists
from gnomemusic.grilo import grilo
-from gnomemusic import log
+from gnomemusic import log, RateLimited
import logging
logger = logging.getLogger(__name__)
@@ -136,6 +136,7 @@ class Window(Gtk.ApplicationWindow):
GLib.idle_add(self.store_window_size_and_position, widget, priority=GLib.PRIORITY_LOW)
@log
+ @RateLimited(2)
def store_window_size_and_position(self, widget):
size = widget.get_size()
self.settings.set_value('window-size', GLib.Variant('ai', [size[0], size[1]]))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]