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
18 changes: 12 additions & 6 deletions queue_job/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from odoo import _, api, exceptions, fields, models
from odoo.osv import expression
from odoo.tools import config, html_escape
from odoo.tools import config, html_escape, index_exists

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

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

def init(self):
self._cr.execute(
"SELECT indexname FROM pg_indexes WHERE indexname = %s ",
("queue_job_identity_key_state_partial_index",),
)
if not self._cr.fetchone():
index_1 = "queue_job_identity_key_state_partial_index"
index_2 = "queue_job_channel_date_done_date_created_index"
if not index_exists(self._cr, index_1):
# Used by Job.job_record_with_same_identity_key
self._cr.execute(
"CREATE INDEX queue_job_identity_key_state_partial_index "
"ON queue_job (identity_key) WHERE state in ('pending', "
"'enqueued', 'wait_dependencies') AND identity_key IS NOT NULL;"
)
if not index_exists(self._cr, index_2):
# Used by <queue.job>.autovacuum
self._cr.execute(
"CREATE INDEX queue_job_channel_date_done_date_created_index "
"ON queue_job (channel, date_done, date_created);"
)

@api.depends("records")
def _compute_record_ids(self):
Expand Down Expand Up @@ -396,6 +401,7 @@ def autovacuum(self):
("date_cancelled", "<=", deadline),
("channel", "=", channel.complete_name),
],
order="date_done, date_created",
limit=1000,
)
if jobs:
Expand Down