Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions partner_tag_smart_assignation/models/res_partner_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ResPartnerCategory(models.Model):
"partner_id",
)

tagged_partner_count = fields.Integer(compute="_compute_number_tags", stored=True)
tagged_partner_count = fields.Integer(compute="_compute_number_tags")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Removing store=True can lead to significant performance degradation (the N+1 problem) when this field is used in a list view, as it would cause a separate database query for each row. It is highly recommended to keep store=True for performance reasons. If the stored value was not being updated correctly, the root cause of that issue should be investigated and fixed instead. If making this field non-stored is absolutely necessary, the compute method _compute_number_tags must be refactored to be batch-friendly to avoid the N+1 problem.


author_id = fields.Many2one(
"res.users", string="Author", default=lambda x: x.env.user
Expand All @@ -56,17 +56,15 @@ class ResPartnerCategory(models.Model):
def create(self, vals):
record = super().create(vals)
record.with_delay(
channel="root.res_partner",
priority=100
channel="root.res_partner", priority=100
).update_partner_tags()
return record

def write(self, vals):
res = super().write(vals)
if "tag_filter_condition_id" in vals or "model" in vals:
self.with_delay(
channel="root.res_partner",
priority=100
channel="root.res_partner", priority=100
).update_partner_tags()
return res

Expand Down
Loading