Modify

Opened 7 years ago

Closed 7 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): 
    202202        """Determines the new owner"""
    203203        db = self.env.get_db_cnx()
    204204        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, ))
    207208        row = cursor.fetchone()
    208209        if row:
    209210            owner = row[0]
    class TicketWorkflowOpStatusPrevious(TicketWorkflowOpBase): 
    250251        """Determines the new status"""
    251252        db = self.env.get_db_cnx()
    252253        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, ))
    255257        row = cursor.fetchone()
    256258        if row:
    257259            status = row[0]

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by Jun Omae

Resolution: fixed
Status: newclosed

In 16303:

AdvancedTicketWorkflowPlugin/0.12: avoid expression on ORDER BY clause to use index of ticket_change (closes #13100)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Eli Carter.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.