Modify ↓
Opened 8 years ago
Closed 8 years ago
#13100 closed defect (fixed)
Expression on "ORDER BY" clause is used
Reported by: | Jun Omae | Owned by: | Eli Carter |
---|---|---|---|
Priority: | normal | Component: | AdvancedTicketWorkflowPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 0.12 |
Description
The ORDER BY -time
clause prevents using index of ticket_change. We could use ORDER BY time DESC
. Also, it seems only first row is needed since use of fetchone()
. We could use LIMIT 1
.
-
advancedworkflow/controller.py
diff --git a/advancedworkflow/controller.py b/advancedworkflow/controller.py index d8cac545b..43a4c463c 100644
a b class TicketWorkflowOpOwnerPrevious(TicketWorkflowOpBase): 202 202 """Determines the new owner""" 203 203 db = self.env.get_db_cnx() 204 204 cursor = db.cursor() 205 cursor.execute("SELECT oldvalue FROM ticket_change WHERE ticket=%s " \ 206 "AND field='owner' ORDER BY -time", (ticket.id, )) 205 cursor.execute("SELECT oldvalue FROM ticket_change WHERE ticket=%s " 206 "AND field='owner' ORDER BY time DESC LIMIT 1", 207 (ticket.id, )) 207 208 row = cursor.fetchone() 208 209 if row: 209 210 owner = row[0] … … class TicketWorkflowOpStatusPrevious(TicketWorkflowOpBase): 250 251 """Determines the new status""" 251 252 db = self.env.get_db_cnx() 252 253 cursor = db.cursor() 253 cursor.execute("SELECT oldvalue FROM ticket_change WHERE ticket=%s " \ 254 "AND field='status' ORDER BY -time", (ticket.id, )) 254 cursor.execute("SELECT oldvalue FROM ticket_change WHERE ticket=%s " 255 "AND field='status' ORDER BY time DESC LIMIT 1", 256 (ticket.id, )) 255 257 row = cursor.fetchone() 256 258 if row: 257 259 status = row[0]
Attachments (0)
Note: See
TracTickets for help on using
tickets.
In 16303: