##// END OF EJS Templates
db: move Session.remove to outer wsgi layer and also add it...
dan -
r669:d3c76065 stable
parent child Browse files
Show More
@@ -39,6 +39,7 b' from routes.middleware import RoutesMidd'
39 39 import routes.util
40 40
41 41 import rhodecode
42 from rhodecode.model import meta
42 43 from rhodecode.config import patches
43 44 from rhodecode.config.routing import STATIC_FILE_PREFIX
44 45 from rhodecode.config.environment import (
@@ -158,6 +159,10 b' def make_pyramid_app(global_config, **se'
158 159 pyramid_app = config.make_wsgi_app()
159 160 pyramid_app = wrap_app_in_wsgi_middlewares(pyramid_app, config)
160 161 pyramid_app.config = config
162
163 # creating the app uses a connection - return it after we are done
164 meta.Session.remove()
165
161 166 return pyramid_app
162 167
163 168
@@ -374,7 +379,25 b' def wrap_app_in_wsgi_middlewares(pyramid'
374 379 pyramid_app = make_gzip_middleware(
375 380 pyramid_app, settings, compress_level=1)
376 381
377 return pyramid_app
382
383 # this should be the outer most middleware in the wsgi stack since
384 # middleware like Routes make database calls
385 def pyramid_app_with_cleanup(environ, start_response):
386 try:
387 return pyramid_app(environ, start_response)
388 finally:
389 # Dispose current database session and rollback uncommitted
390 # transactions.
391 meta.Session.remove()
392
393 # In a single threaded mode server, on non sqlite db we should have
394 # '0 Current Checked out connections' at the end of a request,
395 # if not, then something, somewhere is leaving a connection open
396 pool = meta.Base.metadata.bind.engine.pool
397 log.debug('sa pool status: %s', pool.status())
398
399
400 return pyramid_app_with_cleanup
378 401
379 402
380 403 def sanitize_settings_and_apply_defaults(settings):
@@ -30,6 +30,7 b' import Pyro4'
30 30 import pylons
31 31 import rhodecode
32 32
33 from rhodecode.model import meta
33 34 from rhodecode.lib import hooks_base
34 35 from rhodecode.lib.utils2 import (
35 36 AttributeDict, safe_str, get_routes_generator_for_server_url)
@@ -64,7 +65,10 b' class HooksHttpHandler(BaseHTTPRequestHa'
64 65
65 66 def _call_hook(self, method, extras):
66 67 hooks = Hooks()
67 result = getattr(hooks, method)(extras)
68 try:
69 result = getattr(hooks, method)(extras)
70 finally:
71 meta.Session.remove()
68 72 return result
69 73
70 74 def log_message(self, format, *args):
@@ -406,8 +406,11 b' class SimpleVCS(object):'
406 406 yield chunk
407 407 finally:
408 408 # invalidate cache on push
409 if action == 'push':
410 self._invalidate_cache(repo_name)
409 try:
410 if action == 'push':
411 self._invalidate_cache(repo_name)
412 finally:
413 meta.Session.remove()
411 414
412 415 def _get_repository_name(self, environ):
413 416 """Get repository name out of the environmnent
@@ -40,40 +40,35 b' def pylons_compatibility_tween_factory(h'
40 40 from pyramid. For example while rendering an old template that uses the
41 41 'c' or 'h' objects. This tween sets up the needed pylons globals.
42 42 """
43 try:
44 config = rhodecode.CONFIG
45 environ = request.environ
46 session = request.session
47 session_key = (config['pylons.environ_config']
48 .get('session', 'beaker.session'))
43 config = rhodecode.CONFIG
44 environ = request.environ
45 session = request.session
46 session_key = (config['pylons.environ_config']
47 .get('session', 'beaker.session'))
49 48
50 # Setup pylons globals.
51 pylons.config._push_object(config)
52 pylons.request._push_object(request)
53 pylons.session._push_object(session)
54 environ[session_key] = session
55 pylons.url._push_object(URLGenerator(config['routes.map'],
56 environ))
49 # Setup pylons globals.
50 pylons.config._push_object(config)
51 pylons.request._push_object(request)
52 pylons.session._push_object(session)
53 environ[session_key] = session
54 pylons.url._push_object(URLGenerator(config['routes.map'],
55 environ))
57 56
58 # TODO: Maybe we should use the language from pyramid.
59 translator = _get_translator(config.get('lang'))
60 pylons.translator._push_object(translator)
61
62 # Get the rhodecode auth user object and make it available.
63 auth_user = get_auth_user(environ)
64 request.user = auth_user
65 environ['rc_auth_user'] = auth_user
57 # TODO: Maybe we should use the language from pyramid.
58 translator = _get_translator(config.get('lang'))
59 pylons.translator._push_object(translator)
66 60
67 # Setup the pylons context object ('c')
68 context = ContextObj()
69 context.rhodecode_user = auth_user
70 attach_context_attributes(context, request)
71 pylons.tmpl_context._push_object(context)
72 return handler(request)
73 finally:
74 # Dispose current database session and rollback uncommitted
75 # transactions.
76 meta.Session.remove()
61 # Get the rhodecode auth user object and make it available.
62 auth_user = get_auth_user(environ)
63 request.user = auth_user
64 environ['rc_auth_user'] = auth_user
65
66 # Setup the pylons context object ('c')
67 context = ContextObj()
68 context.rhodecode_user = auth_user
69 attach_context_attributes(context, request)
70 pylons.tmpl_context._push_object(context)
71 return handler(request)
77 72
78 73 return pylons_compatibility_tween
79 74
General Comments 0
You need to be logged in to leave comments. Login now