Commits

Jesper Nøhr committed e22fd55

using sdiff instead now

Comments (0)

Files changed (1)

src/rewsfeed/models.py

         self.conn = redis.Redis(host=host, port=port, password=password)
 
         curried = [ 'hmset', 'exists', 'hgetall',
-                    'sadd', 'srem', 'smembers', 'sdiff',
+                    'sadd', 'srem', 'smembers',
                     'set', 'get',
                     'zadd', 'zrem', 'zcard', 'zrange' ]
         
         def _wrap(*args, **kwargs):
             return fun(self.prefix+args[0], *args[1:], **kwargs)
         return _wrap
+
+    def sdiff(self, args):
+        return self.conn.sdiff([ self.prefix+arg for arg in args ])
     
 class DictAbstracted(object):
     def __init__(self, network, **kwargs):
     # -- 
     
     def following(self):
-        follows = self.network.smembers(User.FOLLOWS_KEY+self.key())
-        blocked = self.network.smembers(User.BLOCKED_KEY+self.key())
+        follows_key = User.FOLLOWS_KEY+self.key()
+        blocked_key = User.BLOCKED_KEY+self.key()
 
-        for user in follows.difference(blocked):
+        for user in self.network.sdiff((follows_key, blocked_key)):
             yield User(self.network, **self.network.hgetall(self.data_key(user)))
 
     def followers(self):
-        followers = self.network.smembers(User.FOLLOWERS_KEY+self.key())
-        blocks = self.network.smembers(User.BLOCKS_KEY+self.key())
+        followers_key = User.FOLLOWERS_KEY+self.key()
+        blocks_key = User.BLOCKS_KEY+self.key()
 
-        for user in followers.difference(blocks):
+        for user in self.network.sdiff((followers_key, blocks_key)):
             yield User(self.network, **self.network.hgetall(self.data_key(user)))
         
     def key(self, extra=''):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.