[IMP] website_forum: improve website/forum count computation

Avoid search_count in a loop using a filtered_domain.

Also removed a sudo, as anyway this method is already called in sudo in
most cases.

Part-of: odoo/odoo#116778
This commit is contained in:
Thibault Delavallée
2023-03-29 23:37:00 +02:00
parent 71dd1d90ee
commit 1d2057806b
+2 -3
View File
@@ -50,7 +50,6 @@ class Website(models.Model):
websites (to update globally counters, notably when a new forum is
created). """
websites = self if self else self.search([])
forums_all = self.env['forum.forum'].search([])
for website in websites:
website.forum_count = self.env['forum.forum'].sudo().search_count(
website.website_domain()
)
website.forum_count = len(forums_all.filtered_domain(website.website_domain()))