comparison sat_pubsub/backend.py @ 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 34adc4a8aa64
comparison
equal deleted inserted replaced
314:1e546442b81a 315:720d73e30bf7
678 d.addCallback(self.checkGroup, requestor) 678 d.addCallback(self.checkGroup, requestor)
679 d.addCallback(access_checked) 679 d.addCallback(access_checked)
680 680
681 return d 681 return d
682 682
683 def _setCount(self, value, response):
684 response.count = value
685
686 def _setIndex(self, value, response):
687 response.index = value
688
683 def _items_rsm(self, elts, node, authorized_groups, unrestricted, maxItems, 689 def _items_rsm(self, elts, node, authorized_groups, unrestricted, maxItems,
684 itemIdentifiers, request): 690 itemIdentifiers, request):
685 # FIXME: move this to a separate module ? 691 # FIXME: move this to a separate module ?
686 response = rsm.RSMResponse() 692 response = rsm.RSMResponse()
687 693
688 d_count = node.countItems(authorized_groups, unrestricted) 694 d_count = node.countItems(authorized_groups, unrestricted)
689 d_count.addCallback(lambda count: setattr(response, 'count', count)) 695 d_count.addCallback(self._setCount, response)
690 d_list = [d_count] 696 d_list = [d_count]
691 697
692 if request.index is not None: 698 if request.index is not None:
693 response.index = request.index 699 response.index = request.index
694 elif request.before is not None: 700 elif request.before is not None:
695 if request.before != '': 701 if request.before != '':
696 # XXX: getIndex starts with index 1, RSM starts with 0 702 # XXX: getIndex starts with index 1, RSM starts with 0
697 d_index = node.getIndex(authorized_groups, unrestricted, request.before) 703 d_index = node.getIndex(authorized_groups, unrestricted, request.before)
698 d_index.addCallback(lambda index: setattr(response, 'index', max(index - request.max - 1, 0))) 704 d_index.addCallback(lambda index: max(index - request.max - 1, 0))
705 d_index.addCallback(self._setIndex, response)
699 d_list.append(d_index) 706 d_list.append(d_index)
700 elif request.after is not None: 707 elif request.after is not None:
701 d_index = node.getIndex(authorized_groups, unrestricted, request.after) 708 d_index = node.getIndex(authorized_groups, unrestricted, request.after)
702 d_index.addCallback(lambda index: setattr(response, 'index', index)) 709 d_index.addCallback(self._setIndex, response)
703 d_list.append(d_index) 710 d_list.append(d_index)
704 elif itemIdentifiers: 711 elif itemIdentifiers:
705 d_index = node.getIndex(authorized_groups, unrestricted, itemIdentifiers[0]) 712 d_index = node.getIndex(authorized_groups, unrestricted, itemIdentifiers[0])
706 d_index.addCallback(lambda index: setattr(response, 'index', index - 1)) 713 d_index.addCallback(lambda index: index - 1)
714 d_index.addCallback(self._setIndex, response)
707 d_list.append(d_index) 715 d_list.append(d_index)
708 716
709 717
710 def render(result): 718 def render(result):
711 try: 719 try: