Skip to content

Commit

Permalink
Avoid calling time.time() for every row when sorting TreeWidgets. (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoTavares committed Oct 28, 2020
1 parent 4e09df0 commit 4d8451a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cuegui/cuegui/AbstractWidgetItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import cuegui.Logger
import cuegui.Style

import opencue

logger = cuegui.Logger.getLogger(__file__)

Expand Down Expand Up @@ -88,7 +89,8 @@ def __lt__(self, other):
"""Custom sorting for columns that have a function defined for sorting"""
sortLambda = self.column_info[self.treeWidget().sortColumn()][SORT_LAMBDA]
column = self.treeWidget().sortColumn()
if sortLambda:

if sortLambda and isinstance(other.rpcObject, opencue.wrappers.job.Job):
try:
return sortLambda(self.rpcObject) < sortLambda(other.rpcObject)
except:
Expand Down
6 changes: 4 additions & 2 deletions cuegui/cuegui/CueJobMonitorTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class CueJobMonitorTree(cuegui.AbstractTreeWidget.AbstractTreeWidget):
def __init__(self, parent):

self.__shows = {}
self.currtime = time.time()

self.startColumnsForType(cuegui.Constants.TYPE_JOB)
self.addColumn("Job", 550, id=1,
Expand Down Expand Up @@ -115,8 +116,8 @@ def __init__(self, parent):
tip="The maximum number of running cores that the cuebot\n"
"will allow.")
self.addColumn("Age", 50, id=11,
data=lambda job: cuegui.Utils.secondsToHHHMM(time.time() - job.data.start_time),
sort=lambda job: time.time() - job.data.start_time,
data=lambda job: cuegui.Utils.secondsToHHHMM(self.currtime - job.data.start_time),
sort=lambda job: self.currtime - job.data.start_time,
tip="The HOURS:MINUTES since the job was launched.")
self.addColumn("Pri", 30, id=12,
data=lambda job: job.data.priority,
Expand Down Expand Up @@ -340,6 +341,7 @@ def _getUpdate(self):
@rtype: [list<NestedGroup>, set(str)]
@return: List that contains updated nested groups and a set of all
updated item ideas"""
self.currtime = time.time()
try:
groups = [show.getJobWhiteboard() for show in self.getShows()]
nestedGroups = []
Expand Down

0 comments on commit 4d8451a

Please sign in to comment.