Commits

Jesper Nøhr committed e22fd55

using sdiff instead now

  • Participants
  • Parent commits 9c95af4

Comments (0)

Files changed (1)

File 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=''):