##// END OF EJS Templates
reverted copy of cached instance:...
marcink -
r1340:cbdd583f beta
parent child Browse files
Show More
@@ -1,81 +1,74
1 1 """The base Controller API
2 2
3 3 Provides the BaseController class for subclassing.
4 4 """
5 import copy
6
7 5 from pylons import config, tmpl_context as c, request, session
8 6 from pylons.controllers import WSGIController
9 7 from pylons.templating import render_mako as render
10 8
11 9 from rhodecode import __version__
12 10 from rhodecode.lib.auth import AuthUser
13 11 from rhodecode.lib.utils import get_repo_slug
14 12 from rhodecode.model import meta
15 13 from rhodecode.model.scm import ScmModel
16 14 from rhodecode import BACKENDS
17 15
18 16
19 17 class BaseController(WSGIController):
20 18
21 19 def __before__(self):
22 20 c.rhodecode_version = __version__
23 21 c.rhodecode_name = config.get('rhodecode_title')
24 22 c.ga_code = config.get('rhodecode_ga_code')
25 23 c.repo_name = get_repo_slug(request)
26 24 c.backends = BACKENDS.keys()
27 25 self.cut_off_limit = int(config.get('cut_off_limit'))
28 26
29 27 self.sa = meta.Session()
30 28 self.scm_model = ScmModel(self.sa)
31 29 c.cached_repo_list = self.scm_model.get_repos()
32 30 #c.unread_journal = scm_model.get_unread_journal()
33 31
34 32 def __call__(self, environ, start_response):
35 33 """Invoke the Controller"""
36 34 # WSGIController.__call__ dispatches to the Controller method
37 35 # the request is routed to. This routing information is
38 36 # available in environ['pylons.routes_dict']
39 37 try:
40 38 # putting this here makes sure that we update permissions each time
41 39 api_key = request.GET.get('api_key')
42 40 user_id = getattr(session.get('rhodecode_user'), 'user_id', None)
43 41 self.rhodecode_user = c.rhodecode_user = AuthUser(user_id, api_key)
44 42 self.rhodecode_user.set_authenticated(
45 43 getattr(session.get('rhodecode_user'),
46 44 'is_authenticated', False))
47 45 session['rhodecode_user'] = self.rhodecode_user
48 46 session.save()
49 47 return WSGIController.__call__(self, environ, start_response)
50 48 finally:
51 49 meta.Session.remove()
52 50
53 51
54 52 class BaseRepoController(BaseController):
55 53 """
56 54 Base class for controllers responsible for loading all needed data
57 55 for those controllers, loaded items are
58 56
59 57 c.rhodecode_repo: instance of scm repository (taken from cache)
60 58
61 59 """
62 60
63 61 def __before__(self):
64 62 super(BaseRepoController, self).__before__()
65 63 if c.repo_name:
66 64
67 r, dbrepo = self.scm_model.get(c.repo_name, retval='repo')
65 c.rhodecode_repo, dbrepo = self.scm_model.get(c.repo_name, retval='repo')
68 66
69 if r is not None:
67 if c.rhodecode_repo is not None:
70 68 c.repository_followers = \
71 69 self.scm_model.get_followers(c.repo_name)
72 70 c.repository_forks = self.scm_model.get_forks(c.repo_name)
73 71 else:
74 72 c.repository_followers = 0
75 73 c.repository_forks = 0
76 74
77 # Since RhodeCode uses heavy memory caching we make a deepcopy
78 # of object taken from cache. This way we lose reference to cached
79 # instance in memory and keep it relatively small even for
80 # very large number of changesets
81 c.rhodecode_repo = copy.copy(r)
General Comments 0
You need to be logged in to leave comments. Login now