Commit c41798ce authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Use cachingMethod to not over query the catalog too much.

parent bd5bfca7
# HARDCODED LIMIT TO BE MOVED TO GLOBAL PREFERENCES
from Products.ERP5Type.Cache import CachingMethod
portal = context.getPortalObject()
limit = portal.portal_preferences.getPreferredSupportRequestCreationLimit(5)
def isSupportRequestCreationClosed(destination_decision=None):
limit = portal.portal_preferences.getPreferredSupportRequestCreationLimit(5)
kw['limit'] = limit
kw['portal_type'] = 'Support Request'
kw['simulation_state'] = ["validated","submitted"]
kw['default_resource_uid'] = portal.service_module.slapos_crm_monitoring.getUid()
if destination_decision:
kw['default_destination_decision_uid'] = context.restrictedTraverse(
destination_decision).getUid()
kw = {}
kw['limit'] = limit
kw['portal_type'] = 'Support Request'
kw['simulation_state'] = ["validated","submitted"]
kw['default_resource_uid'] = portal.service_module.slapos_crm_monitoring.getUid()
if destination_decision:
kw['default_destination_decision_uid'] = context.restrictedTraverse(
destination_decision).getUid()
support_request_list = context.portal_catalog(**kw)
support_request_amount = context.portal_catalog.countResults(**kw)[0][0]
return support_request_amount >= limit
return len(support_request_list) >= limit
return CachingMethod(isSupportRequestCreationClosed,
"isSupportRequestCreationClosed")(destination_decision=destination_decision)
......@@ -2221,6 +2221,9 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin):
newSupportRequest()
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
newSupportRequest()
# It hit cache
self.assertFalse(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
self.clearCache()
self.assertTrue(self.portal.ERP5Site_isSupportRequestCreationClosed(url))
self.assertTrue(self.portal.ERP5Site_isSupportRequestCreationClosed())
......
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