[PATCH 2/2] Issue #737: fix to remove multiple calls of resource lookup in GET

From: Archana Singh <archus@linux.vnet.ibm.com> Incase of GET lookup was called twice.Once lookup() before is_authorized() and then in self.get(). This added overhead to system when lookup() is called for each value in list from get_list() of Collection. So to avoid this overhead, lookup() should not be called before self.get(). And hence it make sense to call lookup() from get(), update(), delete() separately. And as is_authorized() used self.info, which is currently being intialized in exception section of lookup(). It make more sense to intialize it in __init__. Signed-off-by: Archana Singh <archus@linux.vnet.ibm.com> --- src/wok/control/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wok/control/base.py b/src/wok/control/base.py index 5c5c95f..4a4220f 100644 --- a/src/wok/control/base.py +++ b/src/wok/control/base.py @@ -58,6 +58,7 @@ class Resource(object): self.model_args = (ident,) self.role_key = None self.admin_methods = [] + self.info = {} def _redirect(self, action_result, code=303): if isinstance(action_result, list): @@ -145,6 +146,7 @@ class Resource(object): def delete(self): try: + self.lookup() fn = getattr(self.model, model_fn(self, 'delete')) fn(*self.model_args) cherrypy.response.status = 204 @@ -163,7 +165,6 @@ class Resource(object): self.role_key, self.admin_methods) try: - self.lookup() if not self.is_authorized(): raise UnauthorizedError('WOKAPI0009E') @@ -198,6 +199,7 @@ class Resource(object): def update(self, *args, **kargs): try: + self.lookup() update = getattr(self.model, model_fn(self, 'update')) except AttributeError: e = InvalidOperation('WOKAPI0003E', {'resource': -- 2.1.0

Is it a V2 from the previous patch? What are the differences from the previous patch? One more question below: On 10/10/2015 07:32, archus@linux.vnet.ibm.com wrote:
From: Archana Singh <archus@linux.vnet.ibm.com>
Incase of GET lookup was called twice.Once lookup() before is_authorized() and then in self.get(). This added overhead to system when lookup() is called for each value in list from get_list() of Collection. So to avoid this overhead, lookup() should not be called before self.get(). And hence it make sense to call lookup() from get(), update(), delete() separately. And as is_authorized() used self.info, which is currently being intialized in exception section of lookup(). It make more sense to intialize it in __init__.
Signed-off-by: Archana Singh <archus@linux.vnet.ibm.com> --- src/wok/control/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/wok/control/base.py b/src/wok/control/base.py index 5c5c95f..4a4220f 100644 --- a/src/wok/control/base.py +++ b/src/wok/control/base.py @@ -58,6 +58,7 @@ class Resource(object): self.model_args = (ident,) self.role_key = None self.admin_methods = [] + self.info = {}
def _redirect(self, action_result, code=303): if isinstance(action_result, list): @@ -145,6 +146,7 @@ class Resource(object):
def delete(self): try: + self.lookup() fn = getattr(self.model, model_fn(self, 'delete')) fn(*self.model_args) cherrypy.response.status = 204 @@ -163,7 +165,6 @@ class Resource(object): self.role_key, self.admin_methods)
try: - self.lookup() if not self.is_authorized(): raise UnauthorizedError('WOKAPI0009E')
@@ -198,6 +199,7 @@ class Resource(object):
def update(self, *args, **kargs): try: + self.lookup()
What is it needed?
update = getattr(self.model, model_fn(self, 'update')) except AttributeError: e = InvalidOperation('WOKAPI0003E', {'resource':
participants (2)
-
Aline Manera
-
archus@linux.vnet.ibm.com