From c165bfd18efa342e4d9b78899cada79177e0c037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alix?= Date: Wed, 6 Mar 2024 12:03:03 +0100 Subject: [PATCH] [FIX] queue_job: fix partial index to add 'wait_dependencies' state The identity key lookup searches in the 'wait_dependencies', 'pending' and 'enqueued' states, but the partial index only covers 'pending' and 'enqueued', so PostgreSQL can never use it and falls back to the state index, filtering every waiting job on its identity key. The pre-migration only drops the index when it misses the 'wait_dependencies' state, so an index already rebuilt beforehand (e.g. concurrently, on a big queue_job table) is kept as is. (cherry picked from commit fe4fe951341e4b1c15e18c48da284c1a725f3751) Assisted-by: Claude Opus 5.5 --- queue_job/__manifest__.py | 2 +- .../migrations/12.0.4.1.2/pre-migration.py | 19 +++++++++++++++++++ queue_job/models/queue_job.py | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 queue_job/migrations/12.0.4.1.2/pre-migration.py diff --git a/queue_job/__manifest__.py b/queue_job/__manifest__.py index ddc19b44da..be41d4bff3 100644 --- a/queue_job/__manifest__.py +++ b/queue_job/__manifest__.py @@ -2,7 +2,7 @@ {'name': 'Job Queue', - 'version': '12.0.4.1.1', + 'version': '12.0.4.1.2', 'author': 'Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/queue', 'license': 'LGPL-3', diff --git a/queue_job/migrations/12.0.4.1.2/pre-migration.py b/queue_job/migrations/12.0.4.1.2/pre-migration.py new file mode 100644 index 0000000000..704bad1ab9 --- /dev/null +++ b/queue_job/migrations/12.0.4.1.2/pre-migration.py @@ -0,0 +1,19 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html) + +from odoo.tools.sql import table_exists + + +def migrate(cr, version): + if not table_exists(cr, "queue_job"): + return + # Drop index 'queue_job_identity_key_state_partial_index' when it misses + # the 'wait_dependencies' state, it will be recreated during the update. + # An index already built with the new predicate (e.g. created + # concurrently beforehand on a big table) is kept. + cr.execute( + "SELECT indexdef FROM pg_indexes " + "WHERE indexname = 'queue_job_identity_key_state_partial_index'" + ) + row = cr.fetchone() + if row and "wait_dependencies" not in row[0]: + cr.execute("DROP INDEX queue_job_identity_key_state_partial_index;") diff --git a/queue_job/models/queue_job.py b/queue_job/models/queue_job.py index ba3a3acfc4..abb4a9d1e6 100644 --- a/queue_job/models/queue_job.py +++ b/queue_job/models/queue_job.py @@ -148,7 +148,7 @@ def init(self): self._cr.execute( "CREATE INDEX queue_job_identity_key_state_partial_index " "ON queue_job (identity_key) WHERE state in ('pending', " - "'enqueued') AND identity_key IS NOT NULL;" + "'enqueued', 'wait_dependencies') AND identity_key IS NOT NULL;" ) @api.depends("records")