|
7 | 7 |
|
8 | 8 | from odoo import _, api, exceptions, fields, models |
9 | 9 | from odoo.osv import expression |
10 | | -from odoo.tools import config, html_escape |
| 10 | +from odoo.tools import config, html_escape, index_exists |
11 | 11 |
|
12 | 12 | from odoo.addons.base_sparse_field.models.fields import Serialized |
13 | 13 |
|
@@ -128,16 +128,21 @@ class QueueJob(models.Model): |
128 | 128 | worker_pid = fields.Integer(readonly=True) |
129 | 129 |
|
130 | 130 | 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 |
136 | 135 | self._cr.execute( |
137 | 136 | "CREATE INDEX queue_job_identity_key_state_partial_index " |
138 | 137 | "ON queue_job (identity_key) WHERE state in ('pending', " |
139 | 138 | "'enqueued', 'wait_dependencies') AND identity_key IS NOT NULL;" |
140 | 139 | ) |
| 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 | + ) |
141 | 146 |
|
142 | 147 | @api.depends("dependencies") |
143 | 148 | def _compute_dependency_graph(self): |
|
0 commit comments