Show More
@@ -1,6 +1,6 b'' | |||
|
1 | 1 | ################################################################################ |
|
2 | 2 | ################################################################################ |
|
3 |
# rhodecode - Pylons environment configuration |
|
|
3 | # rhodecode - Pylons environment configuration # | |
|
4 | 4 | # # |
|
5 | 5 | # The %(here)s variable will be replaced with the parent directory of this file# |
|
6 | 6 | ################################################################################ |
@@ -10,7 +10,7 b' debug = true' | |||
|
10 | 10 | ################################################################################ |
|
11 | 11 | ## Uncomment and replace with the address which should receive ## |
|
12 | 12 | ## any error reports after application crash ## |
|
13 |
## Additionally those settings will be used by rhodecode mailing system |
|
|
13 | ## Additionally those settings will be used by rhodecode mailing system ## | |
|
14 | 14 | ################################################################################ |
|
15 | 15 | #email_to = admin@localhost |
|
16 | 16 | #error_email_from = paste_error@localhost |
@@ -49,14 +49,25 b' cache_dir = %(here)s/data' | |||
|
49 | 49 | #################################### |
|
50 | 50 | beaker.cache.data_dir=/%(here)s/data/cache/data |
|
51 | 51 | beaker.cache.lock_dir=/%(here)s/data/cache/lock |
|
52 | beaker.cache.regions=super_short_term,short_term,long_term | |
|
52 | beaker.cache.regions=super_short_term,short_term,long_term,sql_cache_short,sql_cache_med,sql_cache_long | |
|
53 | 53 | beaker.cache.long_term.type=memory |
|
54 | 54 | beaker.cache.long_term.expire=36000 |
|
55 | ||
|
55 | 56 | beaker.cache.short_term.type=memory |
|
56 | 57 | beaker.cache.short_term.expire=60 |
|
58 | ||
|
57 | 59 | beaker.cache.super_short_term.type=memory |
|
58 | 60 | beaker.cache.super_short_term.expire=10 |
|
59 | 61 | |
|
62 | beaker.cache.sql_cache_short.type=memory | |
|
63 | beaker.cache.sql_cache_short.expire=5 | |
|
64 | ||
|
65 | beaker.cache.sql_cache_med.type=memory | |
|
66 | beaker.cache.sql_cache_med.expire=360 | |
|
67 | ||
|
68 | beaker.cache.sql_cache_long.type=file | |
|
69 | beaker.cache.sql_cache_long.expire=3600 | |
|
70 | ||
|
60 | 71 | #################################### |
|
61 | 72 | ### BEAKER SESSION #### |
|
62 | 73 | #################################### |
@@ -1,6 +1,6 b'' | |||
|
1 | 1 | ################################################################################ |
|
2 | 2 | ################################################################################ |
|
3 |
# rhodecode - Pylons environment configuration |
|
|
3 | # rhodecode - Pylons environment configuration # | |
|
4 | 4 | # # |
|
5 | 5 | # The %(here)s variable will be replaced with the parent directory of this file# |
|
6 | 6 | ################################################################################ |
@@ -9,8 +9,8 b'' | |||
|
9 | 9 | debug = true |
|
10 | 10 | ################################################################################ |
|
11 | 11 | ## Uncomment and replace with the address which should receive ## |
|
12 |
## any error reports after application crash |
|
|
13 |
## Additionally those settings will be used by rhodecode mailing system |
|
|
12 | ## any error reports after application crash ## | |
|
13 | ## Additionally those settings will be used by rhodecode mailing system ## | |
|
14 | 14 | ################################################################################ |
|
15 | 15 | #email_to = admin@localhost |
|
16 | 16 | #error_email_from = paste_error@localhost |
@@ -49,14 +49,25 b' cache_dir = %(here)s/data' | |||
|
49 | 49 | #################################### |
|
50 | 50 | beaker.cache.data_dir=/%(here)s/data/cache/data |
|
51 | 51 | beaker.cache.lock_dir=/%(here)s/data/cache/lock |
|
52 | beaker.cache.regions=super_short_term,short_term,long_term | |
|
52 | beaker.cache.regions=super_short_term,short_term,long_term,sql_cache_short,sql_cache_med,sql_cache_long | |
|
53 | 53 | beaker.cache.long_term.type=memory |
|
54 | 54 | beaker.cache.long_term.expire=36000 |
|
55 | ||
|
55 | 56 | beaker.cache.short_term.type=memory |
|
56 | 57 | beaker.cache.short_term.expire=60 |
|
58 | ||
|
57 | 59 | beaker.cache.super_short_term.type=memory |
|
58 | 60 | beaker.cache.super_short_term.expire=10 |
|
59 | 61 | |
|
62 | beaker.cache.sql_cache_short.type=memory | |
|
63 | beaker.cache.sql_cache_short.expire=5 | |
|
64 | ||
|
65 | beaker.cache.sql_cache_med.type=memory | |
|
66 | beaker.cache.sql_cache_med.expire=360 | |
|
67 | ||
|
68 | beaker.cache.sql_cache_long.type=file | |
|
69 | beaker.cache.sql_cache_long.expire=3600 | |
|
70 | ||
|
60 | 71 | #################################### |
|
61 | 72 | ### BEAKER SESSION #### |
|
62 | 73 | #################################### |
@@ -50,14 +50,25 b' app_instance_uuid = ${app_instance_uuid}' | |||
|
50 | 50 | #################################### |
|
51 | 51 | beaker.cache.data_dir=/%(here)s/data/cache/data |
|
52 | 52 | beaker.cache.lock_dir=/%(here)s/data/cache/lock |
|
53 | beaker.cache.regions=super_short_term,short_term,long_term | |
|
53 | beaker.cache.regions=super_short_term,short_term,long_term,sql_cache_short,sql_cache_med,sql_cache_long | |
|
54 | 54 | beaker.cache.long_term.type=memory |
|
55 | 55 | beaker.cache.long_term.expire=36000 |
|
56 | ||
|
56 | 57 | beaker.cache.short_term.type=memory |
|
57 | 58 | beaker.cache.short_term.expire=60 |
|
59 | ||
|
58 | 60 | beaker.cache.super_short_term.type=memory |
|
59 | 61 | beaker.cache.super_short_term.expire=10 |
|
60 | 62 | |
|
63 | beaker.cache.sql_cache_short.type=memory | |
|
64 | beaker.cache.sql_cache_short.expire=5 | |
|
65 | ||
|
66 | beaker.cache.sql_cache_med.type=memory | |
|
67 | beaker.cache.sql_cache_med.expire=360 | |
|
68 | ||
|
69 | beaker.cache.sql_cache_long.type=file | |
|
70 | beaker.cache.sql_cache_long.expire=3600 | |
|
71 | ||
|
61 | 72 | #################################### |
|
62 | 73 | ### BEAKER SESSION #### |
|
63 | 74 | #################################### |
@@ -27,6 +27,7 b' from pylons import config, session, url,' | |||
|
27 | 27 | from pylons.controllers.util import abort, redirect |
|
28 | 28 | from rhodecode.lib.utils import get_repo_slug |
|
29 | 29 | from rhodecode.model import meta |
|
30 | from rhodecode.model.caching_query import FromCache | |
|
30 | 31 | from rhodecode.model.db import User, RepoToPerm, Repository, Permission, \ |
|
31 | 32 | UserToPerm |
|
32 | 33 | from sqlalchemy.exc import OperationalError |
@@ -141,7 +142,9 b' def fill_data(user):' | |||
|
141 | 142 | @param user: |
|
142 | 143 | """ |
|
143 | 144 | sa = meta.Session |
|
144 | dbuser = sa.query(User).get(user.user_id) | |
|
145 | dbuser = sa.query(User).options(FromCache('sql_cache_short', | |
|
146 | 'getuser_%s' % user.user_id))\ | |
|
147 | .get(user.user_id) | |
|
145 | 148 | if dbuser: |
|
146 | 149 | user.username = dbuser.username |
|
147 | 150 | user.is_admin = dbuser.admin |
@@ -166,11 +169,14 b' def fill_perms(user):' | |||
|
166 | 169 | #=========================================================================== |
|
167 | 170 | # fetch default permissions |
|
168 | 171 | #=========================================================================== |
|
172 | default_user = sa.query(User)\ | |
|
173 | .options(FromCache('sql_cache_short','getuser_%s' % 'default'))\ | |
|
174 | .filter(User.username == 'default').scalar() | |
|
175 | ||
|
169 | 176 | default_perms = sa.query(RepoToPerm, Repository, Permission)\ |
|
170 | 177 | .join((Repository, RepoToPerm.repository_id == Repository.repo_id))\ |
|
171 | 178 | .join((Permission, RepoToPerm.permission_id == Permission.permission_id))\ |
|
172 |
.filter(RepoToPerm.user == |
|
|
173 | 'default').scalar()).all() | |
|
179 | .filter(RepoToPerm.user == default_user).all() | |
|
174 | 180 | |
|
175 | 181 | if user.is_admin: |
|
176 | 182 | #======================================================================= |
@@ -18,9 +18,11 b" The rest of what's here are standard SQL" | |||
|
18 | 18 | Beaker constructs. |
|
19 | 19 | |
|
20 | 20 | """ |
|
21 | from beaker.exceptions import BeakerException | |
|
21 | 22 | from sqlalchemy.orm.interfaces import MapperOption |
|
22 | 23 | from sqlalchemy.orm.query import Query |
|
23 | 24 | from sqlalchemy.sql import visitors |
|
25 | import beaker | |
|
24 | 26 | |
|
25 | 27 | class CachingQuery(Query): |
|
26 | 28 | """A Query subclass which optionally loads full results from a Beaker |
@@ -105,7 +107,13 b' def query_callable(manager):' | |||
|
105 | 107 | def query(*arg, **kw): |
|
106 | 108 | return CachingQuery(manager, *arg, **kw) |
|
107 | 109 | return query |
|
108 | ||
|
110 | ||
|
111 | def get_cache_region(name, region): | |
|
112 | if region not in beaker.cache.cache_regions: | |
|
113 | raise BeakerException('Cache region not configured: %s' % region) | |
|
114 | kw = beaker.cache.cache_regions[region] | |
|
115 | return beaker.cache.Cache._get_cache(name, kw) | |
|
116 | ||
|
109 | 117 | def _get_cache_parameters(query): |
|
110 | 118 | """For a query with cache_region and cache_namespace configured, |
|
111 | 119 | return the correspoinding Cache instance and cache key, based |
@@ -125,8 +133,8 b' def _get_cache_parameters(query):' | |||
|
125 | 133 | cache_key = " ".join([str(x) for x in args]) |
|
126 | 134 | |
|
127 | 135 | # get cache |
|
128 | cache = query.cache_manager.get_cache_region(namespace, region) | |
|
129 | ||
|
136 | #cache = query.cache_manager.get_cache_region(namespace, region) | |
|
137 | cache = get_cache_region(namespace, region) | |
|
130 | 138 | # optional - hash the cache_key too for consistent length |
|
131 | 139 | # import uuid |
|
132 | 140 | # cache_key= str(uuid.uuid5(uuid.NAMESPACE_DNS, cache_key)) |
@@ -28,36 +28,6 b' Base = declarative_base()' | |||
|
28 | 28 | #=============================================================================== |
|
29 | 29 | # CACHE OPTIONS |
|
30 | 30 | #=============================================================================== |
|
31 | cache_base = jn(dn(dn(dn(abspath(__file__)))), 'data') | |
|
32 | cache_dir = jn(cache_base, 'cache') | |
|
33 | ||
|
34 | if not os.path.isdir(cache_base): | |
|
35 | os.mkdir(cache_base) | |
|
36 | ||
|
37 | if not os.path.isdir(cache_dir): | |
|
38 | os.mkdir(cache_dir) | |
|
39 | # set start_time to current time | |
|
40 | # to re-cache everything | |
|
41 | # upon application startup | |
|
42 | start_time = time.time() | |
|
43 | # configure the "sqlalchemy" cache region. | |
|
44 | cache_manager.regions['sql_cache_short'] = { | |
|
45 | 'type':'memory', | |
|
46 | 'data_dir':cache_dir, | |
|
47 | 'expire':10, | |
|
48 | 'start_time':start_time | |
|
49 | } | |
|
50 | cache_manager.regions['sql_cache_med'] = { | |
|
51 | 'type':'memory', | |
|
52 | 'data_dir':cache_dir, | |
|
53 | 'expire':360, | |
|
54 | 'start_time':start_time | |
|
55 | } | |
|
56 | cache_manager.regions['sql_cache_long'] = { | |
|
57 | 'type':'file', | |
|
58 | 'data_dir':cache_dir, | |
|
59 | 'expire':3600, | |
|
60 | 'start_time':start_time | |
|
61 | } | |
|
31 | #Configured globally in .ini files | |
|
62 | 32 | #to use cache use this in query |
|
63 | 33 | #.options(FromCache("sqlalchemy_cache_type", "cachekey")) |
General Comments 0
You need to be logged in to leave comments.
Login now