~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-23 22:39:32 UTC
  • mfrom: (13723.2.8 bug724025)
  • Revision ID: launchpad@pqm.canonical.com-20110823223932-6glp2oo6val45mga
[incr] [r=gmb][bug=724025] Speed up an inner loop for BugTask:+index
        with many tasks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
from lazr.uri import URI
76
76
from pytz import utc
77
77
from simplejson import dumps
78
 
from z3c.ptcompat import ViewPageTemplateFile
 
78
from z3c.pt.pagetemplate import ViewPageTemplateFile
79
79
from zope import (
80
80
    component,
81
81
    formlib,
1067
1067
class BugTaskBugWatchMixin:
1068
1068
    """A mixin to be used where a BugTask view displays BugWatch data."""
1069
1069
 
1070
 
    @property
 
1070
    @cachedproperty
1071
1071
    def bug_watch_error_message(self):
1072
1072
        """Return a browser-useable error message for a bug watch."""
1073
1073
        if not self.context.bugwatch:
3383
3383
    target_link_title = None
3384
3384
    many_bugtasks = False
3385
3385
 
 
3386
    template = ViewPageTemplateFile(
 
3387
        '../templates/bugtask-tasks-and-nominations-table-row.pt')
 
3388
 
3386
3389
    def __init__(self, context, request):
3387
3390
        super(BugTaskTableRowView, self).__init__(context, request)
3388
3391
        self.milestone_source = MilestoneVocabulary
3389
3392
 
 
3393
    def initialize(self):
 
3394
        super(BugTaskTableRowView, self).initialize()
 
3395
        link = canonical_url(self.context)
 
3396
        edit_link = link + '/+editstatus'
 
3397
        view_link = link + '/+viewstatus'
 
3398
        can_edit = check_permission('launchpad.Edit', self.context)
 
3399
        task_link = edit_link if can_edit else view_link
 
3400
        bugtask_id = self.context.id
 
3401
        launchbag = getUtility(ILaunchBag)
 
3402
        is_primary = self.context.id == launchbag.bugtask.id
 
3403
        self.data = dict(
 
3404
            # Looking at many_bugtasks is an important optimization.  With
 
3405
            # 150+ bugtasks, it can save three or four seconds of rendering
 
3406
            # time.
 
3407
            expandable=(not self.many_bugtasks and self.canSeeTaskDetails()),
 
3408
            indent_task=ISeriesBugTarget.providedBy(self.context.target),
 
3409
            is_conjoined_slave=self.is_conjoined_slave,
 
3410
            task_link=task_link,
 
3411
            edit_link=edit_link,
 
3412
            view_link=view_link,
 
3413
            can_edit=can_edit,
 
3414
            link=link,
 
3415
            id=bugtask_id,
 
3416
            row_id='tasksummary%d' % bugtask_id,
 
3417
            form_row_id='task%d' % bugtask_id,
 
3418
            row_css_class='highlight' if is_primary else None,
 
3419
            target_link=canonical_url(self.context.target),
 
3420
            target_link_title=self.target_link_title,
 
3421
            user_can_edit_importance=self.context.userCanEditImportance(
 
3422
                self.user),
 
3423
            importance_css_class='importance' + self.context.importance.name,
 
3424
            importance_title=self.context.importance.title,
 
3425
            # We always look up all milestones, so there's no harm
 
3426
            # using len on the list here and avoid the COUNT query.
 
3427
            target_has_milestones=len(self._visible_milestones) > 0,
 
3428
            )
 
3429
 
3390
3430
    def canSeeTaskDetails(self):
3391
3431
        """Whether someone can see a task's status details.
3392
3432
 
3405
3445
                self.context.bug.duplicateof is None and
3406
3446
                not self.is_converted_to_question)
3407
3447
 
3408
 
    def expandable(self):
3409
 
        """Can the task's details be expanded?
3410
 
 
3411
 
        They can if there are not too many bugtasks, and if the user can see
3412
 
        the task details."""
3413
 
        # Looking at many_bugtasks is an important optimization.  With 150+
3414
 
        # bugtasks, it can save three or four seconds of rendering time.
3415
 
        return not self.many_bugtasks and self.canSeeTaskDetails()
3416
 
 
3417
 
    def getTaskRowCSSClass(self):
3418
 
        """The appropriate CSS class for the row in the Affects table.
3419
 
 
3420
 
        Currently this consists solely of highlighting the current context.
3421
 
        """
3422
 
        bugtask = self.context
3423
 
        if bugtask == getUtility(ILaunchBag).bugtask:
3424
 
            return 'highlight'
3425
 
        else:
3426
 
            return None
3427
 
 
3428
 
    def shouldIndentTask(self):
3429
 
        """Should this task be indented in the task listing on the bug page?
3430
 
 
3431
 
        Returns True or False.
3432
 
        """
3433
 
        return ISeriesBugTarget.providedBy(self.context.target)
3434
 
 
3435
 
    def taskLink(self):
3436
 
        """Return the proper link to the bugtask whether it's editable."""
3437
 
        user = getUtility(ILaunchBag).user
3438
 
        bugtask = self.context
3439
 
        if check_permission('launchpad.Edit', user):
3440
 
            return canonical_url(bugtask) + "/+editstatus"
3441
 
        else:
3442
 
            return canonical_url(bugtask) + "/+viewstatus"
3443
 
 
3444
3448
    def _getSeriesTargetNameHelper(self, bugtask):
3445
3449
        """Return the short name of bugtask's targeted series."""
3446
3450
        series = bugtask.distroseries or bugtask.productseries
3535
3539
 
3536
3540
        return items
3537
3541
 
3538
 
    @cachedproperty
3539
 
    def target_has_milestones(self):
3540
 
        """Are there any milestones we can target?
3541
 
 
3542
 
        We always look up all milestones, so there's no harm
3543
 
        using len on the list here and avoid the COUNT query.
3544
 
        """
3545
 
        return len(self._visible_milestones) > 0
3546
 
 
3547
3542
    def bugtask_canonical_url(self):
3548
3543
        """Return the canonical url for the bugtask."""
3549
3544
        return canonical_url(self.context)
3564
3559
        """
3565
3560
        return self.user is not None
3566
3561
 
3567
 
    @property
 
3562
    @cachedproperty
3568
3563
    def user_can_edit_milestone(self):
3569
3564
        """Can the user edit the Milestone field?
3570
3565
 
3602
3597
                    'title': filter.title,
3603
3598
                    'description': filter.description,
3604
3599
                    })
3605
 
 
3606
3600
        # Display the search field only if the user can set any person
3607
3601
        # or team
3608
 
        user = getUtility(ILaunchBag).user
 
3602
        user = self.user
3609
3603
        hide_assignee_team_selection = (
3610
3604
            not self.context.userCanSetAnyAssignee(user) and
3611
3605
            (user is None or user.teams_participated_in.count() == 0))
3612
 
        return dumps({
3613
 
            'row_id': 'tasksummary%s' % self.context.id,
3614
 
            'bugtask_path': '/'.join(
3615
 
                [''] + canonical_url(self.context).split('/')[3:]),
3616
 
            'prefix': get_prefix(self.context),
3617
 
            'assignee_value': self.context.assignee
3618
 
                and self.context.assignee.name,
3619
 
            'assignee_is_team': self.context.assignee
3620
 
                and self.context.assignee.is_team,
3621
 
            'assignee_vocabulary': assignee_vocabulary,
3622
 
            'assignee_vocabulary_filters': filter_details,
3623
 
            'hide_assignee_team_selection': hide_assignee_team_selection,
3624
 
            'user_can_unassign': self.context.userCanUnassign(user),
3625
 
            'target_is_product': IProduct.providedBy(self.context.target),
3626
 
            'status_widget_items': self.status_widget_items,
3627
 
            'status_value': self.context.status.title,
3628
 
            'importance_widget_items': self.importance_widget_items,
3629
 
            'importance_value': self.context.importance.title,
3630
 
            'milestone_widget_items': self.milestone_widget_items,
3631
 
            'milestone_value': (self.context.milestone and
3632
 
                                canonical_url(
3633
 
                                    self.context.milestone,
3634
 
                                    request=IWebServiceClientRequest(
3635
 
                                        self.request)) or
3636
 
                                None),
3637
 
            'user_can_edit_assignee': self.user_can_edit_assignee,
3638
 
            'user_can_edit_milestone': self.user_can_edit_milestone,
3639
 
            'user_can_edit_status': not self.context.bugwatch,
3640
 
            'user_can_edit_importance': (
3641
 
                self.user_can_edit_importance and
3642
 
                not self.context.bugwatch)})
 
3606
        cx = self.context
 
3607
        return dumps(dict(
 
3608
            row_id=self.data['row_id'],
 
3609
            bugtask_path='/'.join([''] + self.data['link'].split('/')[3:]),
 
3610
            prefix=get_prefix(cx),
 
3611
            assignee_value=cx.assignee and cx.assignee.name,
 
3612
            assignee_is_team=cx.assignee and cx.assignee.is_team,
 
3613
            assignee_vocabulary=assignee_vocabulary,
 
3614
            assignee_vocabulary_filters=filter_details,
 
3615
            hide_assignee_team_selection=hide_assignee_team_selection,
 
3616
            user_can_unassign=cx.userCanUnassign(user),
 
3617
            target_is_product=IProduct.providedBy(cx.target),
 
3618
            status_widget_items=self.status_widget_items,
 
3619
            status_value=cx.status.title,
 
3620
            importance_widget_items=self.importance_widget_items,
 
3621
            importance_value=cx.importance.title,
 
3622
            milestone_widget_items=self.milestone_widget_items,
 
3623
            milestone_value=(
 
3624
                canonical_url(
 
3625
                    cx.milestone,
 
3626
                    request=IWebServiceClientRequest(self.request))
 
3627
                if cx.milestone else None),
 
3628
            user_can_edit_assignee=self.user_can_edit_assignee,
 
3629
            user_can_edit_milestone=self.user_can_edit_milestone,
 
3630
            user_can_edit_status=not cx.bugwatch,
 
3631
            user_can_edit_importance=(
 
3632
                self.user_can_edit_importance and not cx.bugwatch)
 
3633
            ))
3643
3634
 
3644
3635
 
3645
3636
class BugsBugTaskSearchListingView(BugTaskSearchListingView):