Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 12 additions & 5 deletions connector_search_engine/models/se_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,14 @@ def _jobify_batch_sync(self, force_export: bool = False) -> None:
description=description, identity_key=identity_exact
).batch_sync(force_export)

def _jobify_batch_recompute(self, force_export: bool = False) -> None:
def _jobify_batch_recompute(
self, force_export: bool = False, binding_ids: list | None = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self, force_export: bool = False, binding_ids: list | None = None
self, force_export: bool = False, binding_ids: list[int] | None = None

) -> None:
self.ensure_one()
description = _("Prepare a batch recompute of index '%s'") % self.name
self.with_delay(
description=description, identity_key=identity_exact
).batch_recompute(force_export)
).batch_recompute(force_export, binding_ids=binding_ids)
Copy link
Member

Choose a reason for hiding this comment

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

Strictly speaking this job description is now inaccurate because it is now a partial recompute? So maybe this method should be split too?


@api.model
def generate_batch_sync_per_index(self, domain: list | None = None) -> None:
Expand Down Expand Up @@ -256,11 +258,16 @@ def _get_domain_for_recomputing_binding(self, force_export: bool = False) -> lis
states.append("recomputing")
return [("index_id", "=", self.id), ("state", "in", states)]

def batch_recompute(self, force_export: bool = False) -> None:
def batch_recompute(
self, force_export: bool = False, binding_ids: list | None = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self, force_export: bool = False, binding_ids: list | None = None
self, force_export: bool = False, binding_ids: list[int] | None = None

Copy link
Member

Choose a reason for hiding this comment

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

What do you think about doing another method? (batch_recompute_bindings_ids?), and factoring out the common part. Less if's is good, in general.

) -> None:
"""Recompute all the bindings of the index marked as to_recompute."""
self.ensure_one()
domain = self._get_domain_for_recomputing_binding(force_export)
bindings = self.env["se.binding"].search(domain)
if binding_ids:
bindings = self.env["se.binding"].browse(binding_ids)
else:
domain = self._get_domain_for_recomputing_binding(force_export)
bindings = self.env["se.binding"].search(domain)
bindings_count = len(bindings)
for batch in bindings._batch(self.batch_recomputing_size):
description = _(
Expand Down
2 changes: 1 addition & 1 deletion connector_search_engine/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def test_life_cycle(self):
trap.assert_enqueued_job(
self.se_index.batch_recompute,
args=(False,),
kwargs={},
kwargs={"binding_ids": None},
properties=dict(
identity_key=identity_exact,
),
Expand Down
9 changes: 8 additions & 1 deletion connector_search_engine/wizards/se_binding_state_updater.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Copyright 2023 ACSONE SA/NV
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo.tools import groupby


class SeBindingStateUpdater(models.TransientModel):
Expand All @@ -14,7 +16,12 @@ class SeBindingStateUpdater(models.TransientModel):
selection=lambda self: self.env["se.binding"]._fields["state"].selection,
required=True,
)
do_it_now = fields.Boolean(help="Don't wait for the cron to process these records")

def doit(self):
res_ids = self.env.context.get("active_ids")
self.env["se.binding"].browse(res_ids).write({"state": self.state})
selected_bindings = self.env["se.binding"].browse(res_ids)
selected_bindings.write({"state": self.state})
if self.do_it_now and self.state == "to_recompute":
for index, bindings in groupby(selected_bindings, key=lambda x: x.index_id):
index._jobify_batch_recompute(binding_ids=[x.id for x in bindings])
8 changes: 7 additions & 1 deletion connector_search_engine/wizards/se_binding_state_updater.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
<field name="arch" type="xml">
<form string="Se Binding State Updater">
<group>
<field name="state" />
<group colspan="2">
<field name="state" />
<field
name="do_it_now"
attrs="{'invisible': [('state', '!=', 'to_recompute')]}"
/>
</group>
</group>
<footer>
<button name="doit" string="OK" class="btn-primary" type="object" />
Expand Down