[orca] Event Manager: Add initial handling for floods and deluges



commit 73ff3dcd8814195288f03674c675d2a844c0718a
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Sun Jun 13 14:06:20 2021 +0200

    Event Manager: Add initial handling for floods and deluges
    
    Some applications can be incredibly spammy and flood us with events
    that grind Orca to a halt. This commit adds initial flood and deluge
    detection handling. It will undoubtedly need to be tweaked.
    
    * Flood: We have more than 100 events in the event queue
    * Deluge: We have more than 250 events in the event queue
    * During a flood, there are some events which we will dequeue, but
      then not send to the script for processing. Rationale: At the time
      we enqueued them, things we're still good; since then things are
      bad and we should move on to more recent events.
    * During a deluge, there are some events which we won't even bother
      enqueuing because things are just awful, and what's the point?
    
    At the present time, the only events that are treated as ignorable are
    text-changed:insert and text-changed:delete for objects that are not the
    locusOfFocus. We always care about events from the locusOfFocus, but
    text-changed spam from other objects (which can come from DOM mutations)
    take too long to process.

 src/orca/event_manager.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
---
diff --git a/src/orca/event_manager.py b/src/orca/event_manager.py
index 4ede0406b..026a7af5a 100644
--- a/src/orca/event_manager.py
+++ b/src/orca/event_manager.py
@@ -130,6 +130,11 @@ class EventManager:
             debug.println(debug.LEVEL_INFO, msg, True)
             return False
 
+        if self._inDeluge() and self._ignoreDuringDeluge(event):
+            msg = 'EVENT MANAGER: Ignoring event type due to deluge'
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return True
+
         script = orca_state.activeScript
         if event.type.startswith('object:children-changed'):
             if not script:
@@ -715,6 +720,46 @@ class EventManager:
 
         return False, "No reason found to activate a different script."
 
+    def _ignoreDuringDeluge(self, event):
+        """Returns true if this event should be ignored during a deluge."""
+
+        ignore = ["object:text-changed:delete",
+                  "object:text-changed:insert"]
+
+        if event.type not in ignore:
+            return False
+
+        return event.source != orca_state.locusOfFocus
+
+    def _inDeluge(self):
+        size = self._eventQueue.qsize()
+        if size > 250:
+            msg = 'EVENT MANAGER: DELUGE! Queue size is %i' % size
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return True
+
+        return False
+
+    def _processDuringFlood(self, event):
+        """Returns true if this event should be processed during a flood."""
+
+        ignore = ["object:text-changed:delete",
+                  "object:text-changed:insert"]
+
+        if event.type not in ignore:
+            return True
+
+        return event.source == orca_state.locusOfFocus
+
+    def _inFlood(self):
+        size = self._eventQueue.qsize()
+        if size > 100:
+            msg = 'EVENT MANAGER: FLOOD? Queue size is %i' % size
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return True
+
+        return False
+
     def _processObjectEvent(self, event):
         """Handles all object events destined for scripts.
 
@@ -771,6 +816,11 @@ class EventManager:
             debug.println(debug.LEVEL_INFO, msg, True)
             return
 
+        if self._inFlood() and not self._processDuringFlood(event):
+            msg = 'EVENT MANAGER: Not processing this event due to flood.'
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return
+
         if eType.startswith('object:selection-changed') \
            and event.source in self._parentsOfDefunctDescendants:
             msg = 'EVENT MANAGER: Ignoring event from parent of defunct descendants'


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]