Speed up the toggling of reviewed/hidden changes

When in the list changes view, if you typed 'v' or 'k' to mark a change
reviewed or hidden, a full refresh of the list view's contents,
including querying the database for all new records, would occur. For
the cases when we're in the Unreviewed changes list, toggling a change
to reviewed should simply remove that change from the listbox, to avoid
doing a full refresh. Same for the hidden toggle.

Storyboard story: 2000085

Change-Id: I76bb439cd5ce386da7d160d3160f36c769a2a99f
This commit is contained in:
Jay Pipes 2014-12-17 17:12:35 -05:00 committed by James E. Blair
parent 77f980b70e
commit 259008cea5

View File

@ -338,6 +338,8 @@ class ChangeListView(urwid.WidgetWrap):
change = session.getChange(change_key)
change.reviewed = not change.reviewed
ret = change.reviewed
reviewed_str = 'reviewed' if change.reviewed else 'unreviewed'
self.log.debug("Set change %s to %s", change_key, reviewed_str)
return ret
def toggleHidden(self, change_key):
@ -345,6 +347,8 @@ class ChangeListView(urwid.WidgetWrap):
change = session.getChange(change_key)
change.hidden = not change.hidden
ret = change.hidden
hidden_str = 'hidden' if change.hidden else 'visible'
self.log.debug("Set change %s to %s", change_key, hidden_str)
return ret
def keypress(self, size, key):
@ -358,15 +362,37 @@ class ChangeListView(urwid.WidgetWrap):
if not len(self.listbox.body):
return None
pos = self.listbox.focus_position
reviewed = self.toggleReviewed(self.listbox.body[pos].change_key)
self.refresh()
change_key = self.listbox.body[pos].change_key
reviewed = self.toggleReviewed(change_key)
if self.unreviewed and reviewed:
# Here we can avoid a full refresh by just removing the particular
# row from the change list if the view is for the unreviewed changes
# only.
row = self.change_rows[change_key]
self.listbox.body.remove(row)
del self.change_rows[change_key]
else:
# Just fall back on doing a full refresh if we're in a situation
# where we're not just popping a row from the list of unreviewed
# changes.
self.refresh()
return None
if keymap.TOGGLE_HIDDEN in commands:
if not len(self.listbox.body):
return None
pos = self.listbox.focus_position
hidden = self.toggleHidden(self.listbox.body[pos].change_key)
self.refresh()
change_key = self.listbox.body[pos].change_key
hidden = self.toggleHidden(change_key)
if hidden:
# Here we can avoid a full refresh by just removing the particular
# row from the change list
row = self.change_rows[change_key]
self.listbox.body.remove(row)
del self.change_rows[change_key]
else:
# Just fall back on doing a full refresh if we're in a situation
# where we're not just popping a row from the list of changes.
self.refresh()
return None
if keymap.REFRESH in commands:
self.app.sync.submitTask(