Skip to content

Commit

Permalink
[saml2: Use own cache as a test was triggered and this is safer
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Apr 15, 2013
1 parent aeb5d1a commit bb1bba2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ckan/logic/auth/__init__.py
Expand Up @@ -11,16 +11,23 @@ def _get_object(context, data_dict, name, class_name):
try:
return context[name]
except KeyError:
model = context['model']
if not data_dict:
data_dict = {}
id = data_dict.get('id', None)
obj = getattr(model, class_name).get(id)
if not obj:
raise logic.NotFound
# Save in case we need this again during the request
context[name] = obj
return obj
key = '_OBJECT_STORE_%s__%s' % (name, id)
# This is our cache key to prevent multiple database calls. Perhaps
# this is a bit too much magic but it feels quite self contained and
# safer that the using current data_dict['id'] magic.
try:
return context[key]
except KeyError:
model = context['model']
obj = getattr(model, class_name).get(id)
if not obj:
raise logic.NotFound
# Save in case we need this again during the request
context[key] = obj
return obj


def get_related_object(context, data_dict=None):
Expand Down

0 comments on commit bb1bba2

Please sign in to comment.