~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/model/bug.py

  • Committer: Robert Collins
  • Date: 2010-09-15 23:40:13 UTC
  • mto: This revision was merged to the branch mainline in revision 11557.
  • Revision ID: robert@canonical.com-20100915234013-ed4kfiuxzfj8yqsu
review feedback.

Show diffs side-by-side

added added

removed removed

Lines of Context:
427
427
    @property
428
428
    def indexed_messages(self):
429
429
        """See `IMessageTarget`."""
430
 
        return self._indexed_messages(content=True)
 
430
        return self._indexed_messages(include_content=True)
431
431
 
432
 
    def _indexed_messages(self, content=False, parents=True):
 
432
    def _indexed_messages(self, include_content=False, include_parents=True):
433
433
        """Get the bugs messages, indexed.
434
434
 
435
 
        :param content: If True retrieve the content for the messages too.
436
 
        :param parents: If True retrieve the content foe parent messages too.
437
 
            If False the parents attribute will be *forced* to None to reduce
438
 
            database lookups.
 
435
        :param include_content: If True retrieve the content for the messages
 
436
            too.
 
437
        :param include_parents: If True retrieve the object for parent messages
 
438
            too. If False the parent attribute will be *forced* to None to
 
439
            reduce database lookups.
439
440
        """
440
441
        # Make all messages be 'in' the main bugtask.
441
442
        inside = self.default_bugtask
442
443
        store = Store.of(self)
443
444
        message_by_id = {}
444
 
        if parents:
 
445
        if include_parents:
445
446
            def to_messages(rows):
446
447
                return [row[0] for row in rows]
447
448
        else:
463
464
            # future we should do that), we do a single separate query
464
465
            # for the message content.
465
466
            message_ids = set(message.id for message in messages)
466
 
            chunks = store.find(MessageChunk,
467
 
                MessageChunk.messageID.is_in(message_ids))
 
467
            chunks = store.find(
 
468
                MessageChunk, MessageChunk.messageID.is_in(message_ids))
468
469
            chunks.order_by(MessageChunk.id)
469
470
            chunk_map = {}
470
471
            for chunk in chunks:
479
480
        def eager_load(rows, slice_info):
480
481
            messages = to_messages(rows)
481
482
            eager_load_owners(messages)
482
 
            if content:
 
483
            if include_content:
483
484
                eager_load_content(messages)
484
485
        def index_message(row, index):
485
486
            # convert row to an IndexedMessage
486
 
            if parents:
 
487
            if include_parents:
487
488
                message, parent = row
488
489
                if parent is not None:
489
490
                    # If there is an IndexedMessage available as parent, use
499
500
            return result
500
501
        # There is possibly some nicer way to do this in storm, but
501
502
        # this is a lot easier to figure out.
502
 
        if parents:
 
503
        if include_parents:
503
504
            ParentMessage = ClassAlias(Message, name="parent_message")
504
 
            tables = SQL("Message left outer join message as parent_message on ("
505
 
                "message.parent=parent_message.id and parent_message.id in (select "
506
 
                "bugmessage.message from bugmessage where bugmessage.bug=%s)), "
507
 
                "BugMessage" % sqlvalues(self.id))
 
505
            tables = SQL("""
 
506
Message left outer join
 
507
message as parent_message on (
 
508
    message.parent=parent_message.id and
 
509
    parent_message.id in (
 
510
        select bugmessage.message from bugmessage where bugmessage.bug=%s)),
 
511
BugMessage""" % sqlvalues(self.id))
508
512
            results = store.using(tables).find(
509
513
                (Message, ParentMessage),
510
514
                BugMessage.bugID == self.id,
1862
1866
        when attachments is evaluated, not when the resultset is processed).
1863
1867
        """
1864
1868
        message_to_indexed = {}
1865
 
        for message in self._indexed_messages(parents=False):
 
1869
        for message in self._indexed_messages(include_parents=False):
1866
1870
            message_to_indexed[message.id] = message
1867
1871
        def set_indexed_message(row):
1868
1872
            attachment = row[0]