diff options
author | Erik Johnston <erik@matrix.org> | 2016-02-18 16:33:07 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-02-18 16:33:07 +0000 |
commit | b8cdec92c77f741aaafa3655e7f4959db7889a3d (patch) | |
tree | 34a7feaa4e17928be5340a23e5283022dd885779 /synapse/util | |
parent | Remove invalid arg. (diff) | |
download | synapse-b8cdec92c77f741aaafa3655e7f4959db7889a3d.tar.xz |
WheelTimer: Don't scan list, use index.
Diffstat (limited to '')
-rw-r--r-- | synapse/util/wheel_timer.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/synapse/util/wheel_timer.py b/synapse/util/wheel_timer.py index b447b2456c..2c9f957616 100644 --- a/synapse/util/wheel_timer.py +++ b/synapse/util/wheel_timer.py @@ -46,11 +46,14 @@ class WheelTimer(object): then (int): When to return the object strictly after. """ then_key = int(then / self.bucket_size) + 1 - for entry in self.entries: - # Add to first bucket we find. This should gracefully handle inserts - # for times in the past. - if entry.end_key >= then_key: - entry.queue.append(obj) + + if self.entries: + min_key = self.entries[0].end_key + max_key = self.entries[-1].end_key + + if then_key <= max_key: + # The max here is to protect against inserts for times in the past + self.entries[max(min_key, then_key) - min_key].queue.append(obj) return next_key = int(now / self.bucket_size) + 1 |