~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/browser/bugtask.py

  • Committer: Graham Binns
  • Date: 2011-09-15 16:31:49 UTC
  • mto: This revision was merged to the branch mainline in revision 14019.
  • Revision ID: graham@canonical.com-20110915163149-vac8fyzc697ok6w8
Batched activity now no longer pulls in results that have already been shown.

Show diffs side-by-side

added added

removed removed

Lines of Context:
679
679
        cache.objects['total_comments_and_activity'] = (
680
680
            self.total_comments + self.total_activity)
681
681
        cache.objects['initial_comment_batch_offset'] = (
682
 
            self.visible_initial_comments)
 
682
            self.visible_initial_comments + 1)
683
683
        cache.objects['first visible_recent_comment'] = (
684
684
            self.total_comments - self.visible_recent_comments)
685
685
 
726
726
    @cachedproperty
727
727
    def comments(self):
728
728
        """Return the bugtask's comments."""
 
729
        return self._getComments()
 
730
 
 
731
    def _getComments(self, slice_info=None):
729
732
        show_spam_controls = check_permission(
730
733
            'launchpad.Admin', self.context.bug)
731
 
        return get_comments_for_bugtask(self.context, truncate=True,
 
734
        return get_comments_for_bugtask(
 
735
            self.context, truncate=True, slice_info=slice_info,
732
736
            for_display=True, show_spam_controls=show_spam_controls)
733
737
 
734
738
    @cachedproperty
735
739
    def interesting_activity(self):
 
740
        return self._getInterestingActivity()
 
741
 
 
742
    def _getInterestingActivity(self, earliest_activity_date=None,
 
743
                                latest_activity_date=None):
736
744
        """A sequence of interesting bug activity."""
 
745
        if (earliest_activity_date is not None and
 
746
            latest_activity_date is not None):
 
747
            # Only get the activity for the date range that we're
 
748
            # interested in to save us from processing too much.
 
749
            activity = self.context.bug.getActivityForDateRange(
 
750
                start_date=earliest_activity_date,
 
751
                end_date=latest_activity_date)
 
752
        else:
 
753
            activity = self.context.bug.activity
737
754
        bug_change_re = (
738
755
            'affects|description|security vulnerability|'
739
756
            'summary|tags|visibility')
742
759
            '(assignee|importance|milestone|status)')
743
760
        interesting_match = re.compile(
744
761
            "^(%s|%s)$" % (bug_change_re, bugtask_change_re)).match
745
 
        return tuple(
 
762
        interesting_activity = tuple(
746
763
            BugActivityItem(activity)
747
 
            for activity in self.context.bug.activity
 
764
            for activity in activity
748
765
            if interesting_match(activity.whatchanged) is not None)
 
766
        # This is a bit kludgy but it means that interesting_activity is
 
767
        # populated correctly for all subsequent calls.
 
768
        self._interesting_activity_cached_value = interesting_activity
 
769
        return interesting_activity
749
770
 
750
771
    def _getEventGroups(self, batch_size=None, offset=None):
751
772
        # Ensure truncation results in < max_length comments as expected
753
774
               + config.malone.comments_list_truncate_newest_to
754
775
               < config.malone.comments_list_max_length)
755
776
 
756
 
        if not self.visible_comments_truncated_for_display:
 
777
        if (not self.visible_comments_truncated_for_display and
 
778
            batch_size is None):
757
779
            comments = self.comments
 
780
        elif batch_size is not None:
 
781
            # If we're limiting to a given set of comments, we work on
 
782
            # just that subset of comments from hereon in, which saves
 
783
            # on processing time a bit.
 
784
            if offset is None:
 
785
                offset = self.visible_initial_comments
 
786
            comments = self._getComments([
 
787
                slice(offset, offset+batch_size)])
758
788
        else:
759
789
            # the comment function takes 0-offset counts where comment 0 is
760
790
            # the initial description, so we need to add one to the limits
761
791
            # to adjust.
762
792
            oldest_count = 1 + self.visible_initial_comments
763
793
            new_count = 1 + self.total_comments - self.visible_recent_comments
764
 
            show_spam_controls = check_permission(
765
 
                'launchpad.Admin', self.context.bug)
766
 
            comments = get_comments_for_bugtask(
767
 
                self.context, truncate=True, for_display=True,
768
 
                slice_info=[
769
 
                    slice(None, oldest_count), slice(new_count, None)],
770
 
                show_spam_controls=show_spam_controls)
 
794
            slice_info = [
 
795
                slice(None, oldest_count), slice(new_count, None)]
 
796
            comments = self._getComments(slice_info)
771
797
 
772
798
        visible_comments = get_visible_comments(
773
799
            comments, user=self.user)
 
800
        if len(visible_comments) > 0 and batch_size is not None:
 
801
            first_comment = visible_comments[0]
 
802
            last_comment = visible_comments[-1]
 
803
            interesting_activity = (
 
804
                self._getInterestingActivity(
 
805
                    earliest_activity_date=first_comment.datecreated,
 
806
                    latest_activity_date=last_comment.datecreated))
 
807
        else:
 
808
            interesting_activity = self.interesting_activity
774
809
 
775
810
        event_groups = group_comments_with_activity(
776
811
            comments=visible_comments,
777
 
            activities=self.interesting_activity,
778
 
            batch_size=batch_size, offset=offset)
 
812
            activities=interesting_activity)
779
813
        return event_groups
780
814
 
781
815
    @cachedproperty
1063
1097
        try:
1064
1098
            return int(self.request.form_ng.getOne('offset'))
1065
1099
        except TypeError:
1066
 
            # We return visible_initial_comments, since otherwise we'd
 
1100
            # We return visible_initial_comments + 1, since otherwise we'd
1067
1101
            # end up repeating comments that are already visible on the
1068
 
            # page.
1069
 
            return self.visible_initial_comments
 
1102
            # page. The +1 accounts for the fact that bug comments are
 
1103
            # essentially indexed from 1 due to comment 0 being the
 
1104
            # initial bug description.
 
1105
            return self.visible_initial_comments + 1
1070
1106
 
1071
1107
    @property
1072
1108
    def batch_size(self):