|
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 |
|
@@ -131,16 +131,21 @@ class QueueJob(models.Model): |
131 | 131 | worker_pid = fields.Integer(readonly=True) |
132 | 132 |
|
133 | 133 | 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 |
139 | 138 | self._cr.execute( |
140 | 139 | "CREATE INDEX queue_job_identity_key_state_partial_index " |
141 | 140 | "ON queue_job (identity_key) WHERE state in ('pending', " |
142 | 141 | "'enqueued', 'wait_dependencies') AND identity_key IS NOT NULL;" |
143 | 142 | ) |
| 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 | + ) |
144 | 149 |
|
145 | 150 | @api.depends("records") |
146 | 151 | def _compute_record_ids(self): |
|
0 commit comments