~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/launchpad/webapp/batching.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2010-08-26 16:02:21 UTC
  • mfrom: (11441.1.1 yet-again-optimized-length)
  • Revision ID: launchpad@pqm.canonical.com-20100826160221-rstb47099sqj7d8u
[r=gmb, abentley,
        noodles775][ui=none] Upgrade to a new version of lazr.restful that's
        optimized to send total_size instead of total_size_link when
        total_size is easy to calculate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
__metaclass__ = type
5
5
 
6
6
import lazr.batchnavigator
 
7
from storm import Undef
7
8
# and ISQLObjectResultSet
8
9
from storm.zope.interfaces import IResultSet
9
10
from zope.component import adapts
10
11
from zope.interface import implements
11
12
from zope.interface.common.sequence import IFiniteSequence
 
13
from zope.security.proxy import removeSecurityProxy
12
14
 
13
15
from canonical.config import config
14
16
from canonical.launchpad.webapp.interfaces import ITableBatchNavigator
30
32
        return iter(self.context)
31
33
 
32
34
    def __len__(self):
 
35
        # XXX 2010-08-24 leonardr bug=620508
 
36
        #
 
37
        # Slicing a ResultSet object returns a copy with ._limit and
 
38
        # ._offset set appropriately. The original object's ._limit
 
39
        # and ._offset are not affected. However, the original and
 
40
        # the copy share a _select object, which means the original
 
41
        # object's ._select.limit and ._select.offset are shared with
 
42
        # the copy.
 
43
        #
 
44
        # This breaks Storm--count() is not supported on a ResultSet
 
45
        # that has a limit or offset set. This code sets
 
46
        # ._select.limit and ._select.offset to the appropriate values
 
47
        # before running the count() query, just as __getitem__ sets
 
48
        # those values before running its query.
 
49
        resultset = removeSecurityProxy(self.context)
 
50
        if hasattr(resultset, '_select'):
 
51
            resultset._select.limit = Undef
 
52
            resultset._select.offset = Undef
33
53
        return self.context.count()
34
54
 
35
55