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

Optimise: minimise amount of catalog calls.

parent 387de7e2
...@@ -372,14 +372,16 @@ class InstancePublisher(GenericPublisher): ...@@ -372,14 +372,16 @@ 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()]))
try:
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.setStatus(200)
self.REQUEST.response.setBody(json.dumps(d)) self.REQUEST.response.setBody(json.dumps(d))
return self.REQUEST.response return self.REQUEST.response
......
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