##// 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 import routes.util
39 import routes.util
40
40
41 import rhodecode
41 import rhodecode
42 from rhodecode.model import meta
42 from rhodecode.config import patches
43 from rhodecode.config import patches
43 from rhodecode.config.routing import STATIC_FILE_PREFIX
44 from rhodecode.config.routing import STATIC_FILE_PREFIX
44 from rhodecode.config.environment import (
45 from rhodecode.config.environment import (
@@ -158,6 +159,10 b' def make_pyramid_app(global_config, **se'
158 pyramid_app = config.make_wsgi_app()
159 pyramid_app = config.make_wsgi_app()
159 pyramid_app = wrap_app_in_wsgi_middlewares(pyramid_app, config)
160 pyramid_app = wrap_app_in_wsgi_middlewares(pyramid_app, config)
160 pyramid_app.config = config
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 return pyramid_app
166 return pyramid_app
162
167
163
168
@@ -374,7 +379,25 b' def wrap_app_in_wsgi_middlewares(pyramid'
374 pyramid_app = make_gzip_middleware(
379 pyramid_app = make_gzip_middleware(
375 pyramid_app, settings, compress_level=1)
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 def sanitize_settings_and_apply_defaults(settings):
403 def sanitize_settings_and_apply_defaults(settings):
@@ -30,6 +30,7 b' import Pyro4'
30 import pylons
30 import pylons
31 import rhodecode
31 import rhodecode
32
32
33 from rhodecode.model import meta
33 from rhodecode.lib import hooks_base
34 from rhodecode.lib import hooks_base
34 from rhodecode.lib.utils2 import (
35 from rhodecode.lib.utils2 import (
35 AttributeDict, safe_str, get_routes_generator_for_server_url)
36 AttributeDict, safe_str, get_routes_generator_for_server_url)
@@ -64,7 +65,10 b' class HooksHttpHandler(BaseHTTPRequestHa'
64
65
65 def _call_hook(self, method, extras):
66 def _call_hook(self, method, extras):
66 hooks = Hooks()
67 hooks = Hooks()
68 try:
67 result = getattr(hooks, method)(extras)
69 result = getattr(hooks, method)(extras)
70 finally:
71 meta.Session.remove()
68 return result
72 return result
69
73
70 def log_message(self, format, *args):
74 def log_message(self, format, *args):
@@ -406,8 +406,11 b' class SimpleVCS(object):'
406 yield chunk
406 yield chunk
407 finally:
407 finally:
408 # invalidate cache on push
408 # invalidate cache on push
409 try:
409 if action == 'push':
410 if action == 'push':
410 self._invalidate_cache(repo_name)
411 self._invalidate_cache(repo_name)
412 finally:
413 meta.Session.remove()
411
414
412 def _get_repository_name(self, environ):
415 def _get_repository_name(self, environ):
413 """Get repository name out of the environmnent
416 """Get repository name out of the environmnent
@@ -40,7 +40,6 b' def pylons_compatibility_tween_factory(h'
40 from pyramid. For example while rendering an old template that uses the
40 from pyramid. For example while rendering an old template that uses the
41 'c' or 'h' objects. This tween sets up the needed pylons globals.
41 'c' or 'h' objects. This tween sets up the needed pylons globals.
42 """
42 """
43 try:
44 config = rhodecode.CONFIG
43 config = rhodecode.CONFIG
45 environ = request.environ
44 environ = request.environ
46 session = request.session
45 session = request.session
@@ -70,10 +69,6 b' def pylons_compatibility_tween_factory(h'
70 attach_context_attributes(context, request)
69 attach_context_attributes(context, request)
71 pylons.tmpl_context._push_object(context)
70 pylons.tmpl_context._push_object(context)
72 return handler(request)
71 return handler(request)
73 finally:
74 # Dispose current database session and rollback uncommitted
75 # transactions.
76 meta.Session.remove()
77
72
78 return pylons_compatibility_tween
73 return pylons_compatibility_tween
79
74
General Comments 0
You need to be logged in to leave comments. Login now