Skip to content

Commit 7942020

Browse files
committed
[IMP] queue_job: add index for efficient autovacuum
1 parent d5f63a0 commit 7942020

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

queue_job/models/queue_job.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from odoo import _, api, exceptions, fields, models
99
from odoo.osv import expression
10-
from odoo.tools import config, html_escape
10+
from odoo.tools import config, html_escape, index_exists
1111

1212
from odoo.addons.base_sparse_field.models.fields import Serialized
1313

@@ -128,16 +128,21 @@ class QueueJob(models.Model):
128128
worker_pid = fields.Integer(readonly=True)
129129

130130
def init(self):
131-
self._cr.execute(
132-
"SELECT indexname FROM pg_indexes WHERE indexname = %s ",
133-
("queue_job_identity_key_state_partial_index",),
134-
)
135-
if not self._cr.fetchone():
131+
index_1 = "queue_job_identity_key_state_partial_index"
132+
index_2 = "queue_job_date_created_date_done_index"
133+
if not index_exists(self._cr, index_1):
134+
# Used by Job.job_record_with_same_identity_key
136135
self._cr.execute(
137136
"CREATE INDEX queue_job_identity_key_state_partial_index "
138137
"ON queue_job (identity_key) WHERE state in ('pending', "
139138
"'enqueued', 'wait_dependencies') AND identity_key IS NOT NULL;"
140139
)
140+
if not index_exists(self._cr, index_2):
141+
# Used by <queue.job>.autovacuum
142+
self._cr.execute(
143+
"CREATE INDEX queue_job_date_created_date_done_index "
144+
"ON queue_job (date_created, date_done);"
145+
)
141146

142147
@api.depends("dependencies")
143148
def _compute_dependency_graph(self):

0 commit comments

Comments
 (0)