~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

  • Committer: William Grant
  • Date: 2010-02-25 03:18:21 UTC
  • Revision ID: grantw@unimelb.edu.au-20100225031821-mi9a2tm5679fht4d
Shuffle things around so that req.user and req.store only construct when actually retrieved, and ensure they're not retrieved for media files. Saves 50ms of DB connection time per request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
    # Make the request object into an IVLE request which can be given to views
127
127
    req = Request(apachereq, config)
128
128
 
129
 
    # Hack? Try and get the user login early just in case we throw an error
130
 
    # (most likely 404) to stop us seeing not logged in even when we are.
131
 
    if not req.publicmode:
132
 
        user = ivle.webapp.security.get_user_details(req)
133
 
 
134
 
        # Don't set the user if it is disabled or hasn't accepted the ToS.
135
 
        if user and user.valid:
136
 
            req.user = user
137
 
 
138
129
    req.publisher = generate_publisher(
139
 
        config.plugin_index[ViewPlugin],
140
 
        ApplicationRoot(req.config, req.store, req.user),
 
130
        config.plugin_index[ViewPlugin], ApplicationRoot(req),
141
131
        publicmode=req.publicmode)
142
132
 
143
133
    try:
201
191
            handle_unknown_exception(req, *sys.exc_info())
202
192
            return req.OK
203
193
        else:
204
 
            req.store.commit()
 
194
            # Commit the transaction if we have a store open.
 
195
            req.commit()
205
196
            return req.OK
206
197
    except Unauthorized, e:
207
198
        # Resolution failed due to a permission check. Display a pretty
219
210
 
220
211
        return req.OK
221
212
    finally:
222
 
        req.store.close()
 
213
        # Make sure we close the store.
 
214
        req.cleanup()
223
215
 
224
216
def handle_unknown_exception(req, exc_type, exc_value, exc_traceback):
225
217
    """