Skip to content

Commit 8e2bd1b

Browse files
committed
[IMP] queue_job: add index for efficient autovacuum
1 parent 81b2cf8 commit 8e2bd1b

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

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

@@ -131,16 +131,21 @@ class QueueJob(models.Model):
131131
worker_pid = fields.Integer(readonly=True)
132132

133133
def init(self):
134-
self._cr.execute(
135-
"SELECT indexname FROM pg_indexes WHERE indexname = %s ",
136-
("queue_job_identity_key_state_partial_index",),
137-
)
138-
if not self._cr.fetchone():
134+
index_1 = "queue_job_identity_key_state_partial_index"
135+
index_2 = "queue_job_date_created_date_done_index"
136+
if not index_exists(index_1):
137+
# Used by Job.job_record_with_same_identity_key
139138
self._cr.execute(
140139
"CREATE INDEX queue_job_identity_key_state_partial_index "
141140
"ON queue_job (identity_key) WHERE state in ('pending', "
142141
"'enqueued', 'wait_dependencies') AND identity_key IS NOT NULL;"
143142
)
143+
if not index_exists(index_2):
144+
# Used by <queue.job>.autovacuum
145+
self._cr.execute(
146+
"CREATE INDEX queue_job_date_created_date_done_index "
147+
"ON queue_job (date_created, date_done);"
148+
)
144149

145150
@api.depends("records")
146151
def _compute_record_ids(self):

0 commit comments

Comments
 (0)