# HG changeset patch # User Goffi # Date 1451842402 -3600 # Node ID 720d73e30bf7fdb006cf6927cd8ae471b5f7bd89 # Parent 1e546442b81a7059baa388ecfb994a42c1d98a81 backend (rsm): replaced setattr use by methods for better performances diff -r 1e546442b81a -r 720d73e30bf7 sat_pubsub/backend.py --- 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)