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
25 changes: 25 additions & 0 deletions queue_job/migrations/19.0.2.5.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
from openupgradelib import openupgrade

# The indexes were created in init() with a free text comment. models.Index compares
# the comment with its own definition and rebuilds the index when they differ, so they
# get the comment the ORM expects and are not rebuilt on the first update.
INDEXES = {
"queue_job_identity_key_state_partial_index": (
"INDEX (identity_key) "
"WHERE state in ('pending','enqueued','wait_dependencies') "
"AND identity_key IS NOT NULL"
),
"queue_job_channel_date_done_date_created_index": (
"INDEX (channel, date_done, date_created)"
),
}


@openupgrade.migrate()
def migrate(env, version):
cr = env.cr
for name, definition in INDEXES.items():
cr.execute("SELECT to_regclass(%s)", [name])
if cr.fetchone()[0]:
cr.execute(f'COMMENT ON INDEX "{name}" IS %s', [definition])
34 changes: 10 additions & 24 deletions queue_job/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from odoo import api, exceptions, fields, models
from odoo.fields import Domain
from odoo.tools import SQL, html_escape
from odoo.tools.sql import create_index

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

Expand Down Expand Up @@ -139,33 +138,20 @@ class QueueJob(models.Model):
readonly=True,
)

channel = fields.Char(index=True)
channel = fields.Char()

identity_key = fields.Char(readonly=True)
worker_pid = fields.Integer(readonly=True)

def init(self):
cr = self.env.cr
# Used by Job.job_record_with_same_identity_key
create_index(
cr,
"queue_job_identity_key_state_partial_index",
"queue_job",
["identity_key"],
where=(
"state in ('pending','enqueued','wait_dependencies') "
"AND identity_key IS NOT NULL"
),
comment=("Queue Job: partial index for identity_key on active states"),
)
# Used by <queue.job>._gc_old_jobs
create_index(
cr,
"queue_job_channel_date_done_date_created_index",
"queue_job",
["channel", "date_done", "date_created"],
comment="Queue Job: index to accelerate autovacuum",
)
# Used by Job.job_record_with_same_identity_key
_identity_key_state_partial_index = models.Index(
"(identity_key) WHERE state in ('pending','enqueued','wait_dependencies') "
"AND identity_key IS NOT NULL"
)
# Used by <queue.job>._gc_old_jobs
_channel_date_done_date_created_index = models.Index(
"(channel, date_done, date_created)"
)

@api.depends("dependencies")
def _compute_dependency_ids(self):
Expand Down
Loading