changeset 315:720d73e30bf7

backend (rsm): replaced setattr use by methods for better performances
author Goffi <goffi@goffi.org>
date Sun, 03 Jan 2016 18:33:22 +0100
parents 1e546442b81a
children cca47e9977a5
files sat_pubsub/backend.py
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/sat_pubsub/backend.py	Sun Jan 03 18:33:22 2016 +0100
+++ b/sat_pubsub/backend.py	Sun Jan 03 18:33:22 2016 +0100
@@ -680,13 +680,19 @@
 
         return d
 
+    def _setCount(self, value, response):
+        response.count = value
+
+    def _setIndex(self, value, response):
+        response.index = value
+
     def _items_rsm(self, elts, node, authorized_groups, unrestricted, maxItems,
                    itemIdentifiers, request):
         # FIXME: move this to a separate module ?
         response = rsm.RSMResponse()
 
         d_count = node.countItems(authorized_groups, unrestricted)
-        d_count.addCallback(lambda count: setattr(response, 'count', count))
+        d_count.addCallback(self._setCount, response)
         d_list = [d_count]
 
         if request.index is not None:
@@ -695,15 +701,17 @@
             if request.before != '':
                 # XXX: getIndex starts with index 1, RSM starts with 0
                 d_index = node.getIndex(authorized_groups, unrestricted, request.before)
-                d_index.addCallback(lambda index: setattr(response, 'index', max(index - request.max - 1, 0)))
+                d_index.addCallback(lambda index: max(index - request.max - 1, 0))
+                d_index.addCallback(self._setIndex, response)
                 d_list.append(d_index)
         elif request.after is not None:
             d_index = node.getIndex(authorized_groups, unrestricted, request.after)
-            d_index.addCallback(lambda index: setattr(response, 'index', index))
+            d_index.addCallback(self._setIndex, response)
             d_list.append(d_index)
         elif itemIdentifiers:
             d_index = node.getIndex(authorized_groups, unrestricted, itemIdentifiers[0])
-            d_index.addCallback(lambda index: setattr(response, 'index', index - 1))
+            d_index.addCallback(lambda index: index - 1)
+            d_index.addCallback(self._setIndex, response)
             d_list.append(d_index)