Commit e87f0e0b authored by Łukasz Nowak's avatar Łukasz Nowak

Optimise: minimise amount of catalog calls.

parent 387de7e2
...@@ -372,16 +372,18 @@ class InstancePublisher(GenericPublisher): ...@@ -372,16 +372,18 @@ class InstancePublisher(GenericPublisher):
kw = dict( kw = dict(
portal_type=('Software Instance', 'Slave Instance'), portal_type=('Software Instance', 'Slave Instance'),
) )
catalog = self.getPortalObject().portal_catalog
if len(catalog(limit=1, **kw)) == 0:
self.REQUEST.response.setStatus(204)
return self.REQUEST.response
d = {"list": []} d = {"list": []}
a = d['list'].append a = d['list'].append
for si in catalog(**kw): for si in self.getPortalObject().portal_catalog(**kw):
a('/'.join([self.absolute_url(), si.getRelativeUrl()])) a('/'.join([self.absolute_url(), si.getRelativeUrl()]))
self.REQUEST.response.setStatus(200) try:
self.REQUEST.response.setBody(json.dumps(d)) d['list'][0]
except IndexError:
# no results, so nothing to return
self.REQUEST.response.setStatus(204)
else:
self.REQUEST.response.setStatus(200)
self.REQUEST.response.setBody(json.dumps(d))
return self.REQUEST.response return self.REQUEST.response
@responseSupport() @responseSupport()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment