~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/codehosting/rewrite.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-04-14 23:57:29 UTC
  • mfrom: (12827.1.3 bug-433888)
  • Revision ID: launchpad@pqm.canonical.com-20110414235729-j7exsjxw07drvlgr
[r=allenap][bug=433888] Set up a request up around line rewrites in
        the branch rewriter making it honour db timeouts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
from zope.component import getUtility
11
11
 
12
12
from canonical.config import config
 
13
from canonical.launchpad.webapp.adapter import (
 
14
    clear_request_started,
 
15
    set_request_started,
 
16
    )
13
17
from lp.code.interfaces.branchlookup import IBranchLookup
14
18
from lp.code.interfaces.codehosting import BRANCH_ID_ALIAS_PREFIX
15
19
from lp.codehosting.vfs import branch_id_to_path
92
96
        # Codebrowse generates references to its images and stylesheets
93
97
        # starting with "/static", so pass them on unthinkingly.
94
98
        T = time.time()
95
 
        cached = None
96
 
        if resource_location.startswith('/static/'):
97
 
            r = self._codebrowse_url(resource_location)
98
 
            cached = 'N/A'
99
 
        else:
100
 
            branch_id, trailing, cached = self._getBranchIdAndTrailingPath(
101
 
                resource_location)
102
 
            if branch_id is None:
103
 
                if resource_location.startswith('/' + BRANCH_ID_ALIAS_PREFIX):
104
 
                    r = 'NULL'
105
 
                else:
106
 
                    r = self._codebrowse_url(resource_location)
 
99
        # Tell the webapp adapter that we are in a request, so that DB
 
100
        # statement timeouts will be applied.
 
101
        set_request_started()
 
102
        try:
 
103
            cached = None
 
104
            if resource_location.startswith('/static/'):
 
105
                r = self._codebrowse_url(resource_location)
 
106
                cached = 'N/A'
107
107
            else:
108
 
                if trailing.startswith('/.bzr'):
109
 
                    r = urlutils.join(
110
 
                        config.codehosting.internal_branch_by_id_root,
111
 
                        branch_id_to_path(branch_id), trailing[1:])
 
108
                branch_id, trailing, cached = self._getBranchIdAndTrailingPath(
 
109
                    resource_location)
 
110
                if branch_id is None:
 
111
                    if resource_location.startswith('/' + BRANCH_ID_ALIAS_PREFIX):
 
112
                        r = 'NULL'
 
113
                    else:
 
114
                        r = self._codebrowse_url(resource_location)
112
115
                else:
113
 
                    r = self._codebrowse_url(resource_location)
 
116
                    if trailing.startswith('/.bzr'):
 
117
                        r = urlutils.join(
 
118
                            config.codehosting.internal_branch_by_id_root,
 
119
                            branch_id_to_path(branch_id), trailing[1:])
 
120
                    else:
 
121
                        r = self._codebrowse_url(resource_location)
 
122
        finally:
 
123
            clear_request_started()
114
124
        self.logger.info(
115
125
            "%r -> %r (%fs, cache: %s)",
116
126
            resource_location, r, time.time() - T, cached)