Custom controller very slow for some users, really slow for others
Question:
We have built a custom controller for a customer which passed products data and loads their products in a custom url.
The controllers are basically like this:
class CustomProducts(http.Controller):
@http.route('/custom', type='http', auth='public', website=True, methods=['GET'])
def render_custom_products(self, **kw):
if kw.get('order'):
if kw.get('order') != "":
order_by = kw.get('order')
else:
order_by = 'list_price desc'
products = http.request.env['product.product'].sudo().search([('categ_id.name', 'ilike', 'Custom'), ('is_published', '=', 'true'), ('active', '=', 'true')],
order= order_by,
limit = 150)
return http.request.render('custom_module.custom_products', {
# pass products details to view
'products': products,
})
EDIT:
This has worked good for over 2 years but suddenly the page is very slow. The weird thing is that the route is very slow for some visitors and very fast (like before) for some. What could be the issue?
Postgres sometimes gives this error:
Could not serialize access due to concurrent update
SELECT * FROM website_visitor where id = XX FOR NO KEY UPDATE NOAWAIT
The customer only have between 30-50 products for sale at once.
Answers:
- You should consider adding logging to note the times
http.request.env['product.product'].sudo().search
seems to be the only function you are calling, so there can be only 2 (i think) causes of the issue –
- Either your search has slowed down
- or you have designed things in a way such that your system is not processing things in parallel
You could could try using fastapi/some other framework – to support async or try to diagnose your search issue depending on further finding.
I really cant make good sense of the solution but it was changing the images in the Qweb view to not display the images using base encoding but to load the images by their URL.
Old:
t-att-src="'data:image/png;base64,%s' % to_text(product.image_512)"
Working:
t-attf-src="/web/image/product.product/{{product.id}}/image_512"
I still dont understand why it was quick for some users and for some sessions on the same machines.
We have built a custom controller for a customer which passed products data and loads their products in a custom url.
The controllers are basically like this:
class CustomProducts(http.Controller):
@http.route('/custom', type='http', auth='public', website=True, methods=['GET'])
def render_custom_products(self, **kw):
if kw.get('order'):
if kw.get('order') != "":
order_by = kw.get('order')
else:
order_by = 'list_price desc'
products = http.request.env['product.product'].sudo().search([('categ_id.name', 'ilike', 'Custom'), ('is_published', '=', 'true'), ('active', '=', 'true')],
order= order_by,
limit = 150)
return http.request.render('custom_module.custom_products', {
# pass products details to view
'products': products,
})
EDIT:
This has worked good for over 2 years but suddenly the page is very slow. The weird thing is that the route is very slow for some visitors and very fast (like before) for some. What could be the issue?
Postgres sometimes gives this error:
Could not serialize access due to concurrent update
SELECT * FROM website_visitor where id = XX FOR NO KEY UPDATE NOAWAIT
The customer only have between 30-50 products for sale at once.
- You should consider adding logging to note the times
http.request.env['product.product'].sudo().search
seems to be the only function you are calling, so there can be only 2 (i think) causes of the issue –
- Either your search has slowed down
- or you have designed things in a way such that your system is not processing things in parallel
You could could try using fastapi/some other framework – to support async or try to diagnose your search issue depending on further finding.
I really cant make good sense of the solution but it was changing the images in the Qweb view to not display the images using base encoding but to load the images by their URL.
Old:
t-att-src="'data:image/png;base64,%s' % to_text(product.image_512)"
Working:
t-attf-src="/web/image/product.product/{{product.id}}/image_512"
I still dont understand why it was quick for some users and for some sessions on the same machines.