[tor-commits] [nyx/master] Cache Entry parameters

atagar at torproject.org atagar at torproject.org
Tue Sep 22 17:08:41 UTC 2015


commit 06f14a56002e365cfab594f1bb065af4e92699b7
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Aug 29 14:29:28 2015 -0700

    Cache Entry parameters
    
    The Entry class is immutable so we can safely cache the hell out of everything.
    No reason to do any work twice.
---
 nyx/connections/entries.py |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/nyx/connections/entries.py b/nyx/connections/entries.py
index 78945f0..579dd5c 100644
--- a/nyx/connections/entries.py
+++ b/nyx/connections/entries.py
@@ -11,6 +11,12 @@ from nyx.util import tor_controller
 from stem.control import Listener
 from stem.util import conf, enum
 
+try:
+  # added in python 3.2
+  from functools import lru_cache
+except ImportError:
+  from stem.util.lru_cache import lru_cache
+
 # attributes we can list entries by
 
 ListingType = enum.Enum(('IP_ADDRESS', 'IP Address'), 'FINGERPRINT', 'NICKNAME')
@@ -37,7 +43,7 @@ def to_unix_time(dt):
   return (dt - datetime.datetime(1970, 1, 1)).total_seconds()
 
 
-class ConnectionPanelEntry:
+class ConnectionPanelEntry(object):
   def __init__(self, connection_type, start_time):
     self.lines = []
     self._connection_type = connection_type
@@ -72,6 +78,7 @@ class ConnectionPanelEntry:
 
     return self._connection_type
 
+  @lru_cache()
   def is_private(self):
     """
     Returns true if the endpoint is private, possibly belonging to a client
@@ -110,6 +117,7 @@ class ConnectionPanelEntry:
 
     return self.lines
 
+  @lru_cache()
   def get_sort_value(self, attr):
     """
     Provides the value of a single attribute used for sorting purposes.





More information about the tor-commits mailing list