Skip to content

Commit

Permalink
Unread count performance optimisation
Browse files Browse the repository at this point in the history
Continuation of Bitmessage#63
  • Loading branch information
mailchuck committed Oct 31, 2015
1 parent 3a4b60b commit 37b79bc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/bitmessageqt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2938,10 +2938,16 @@ def on_action_InboxMarkUnread(self):
font = QFont()
font.setBold(True)
inventoryHashesToMarkUnread = []
modified = 0
for row in tableWidget.selectedIndexes():
currentRow = row.row()
inventoryHashToMarkUnread = str(tableWidget.item(
currentRow, 3).data(Qt.UserRole).toPyObject())
if inventoryHashToMarkUnread in inventoryHashesToMarkUnread:
# it returns columns as separate items, so we skip dupes
continue
if not tableWidget.item(currentRow, 0).font().bold():
modified += 1
inventoryHashesToMarkUnread.append(inventoryHashToMarkUnread)
tableWidget.item(currentRow, 0).setFont(font)
tableWidget.item(currentRow, 1).setFont(font)
Expand All @@ -2950,7 +2956,11 @@ def on_action_InboxMarkUnread(self):
#sqlite requires the exact number of ?s to prevent injection
sqlExecute('''UPDATE inbox SET read=0 WHERE msgid IN (%s)''' % (
"?," * len(inventoryHashesToMarkUnread))[:-1], *inventoryHashesToMarkUnread)
self.propagateUnreadCount(self.getCurrentAccount(), "inbox", self.getCurrentTreeWidget(), 0)
if modified == 1:
# performance optimisation
self.propagateUnreadCount(self.getCurrentAccount())
else:
self.propagateUnreadCount(self.getCurrentAccount(), "inbox", self.getCurrentTreeWidget(), 0)
# tableWidget.selectRow(currentRow + 1)
# This doesn't de-select the last message if you try to mark it unread, but that doesn't interfere. Might not be necessary.
# We could also select upwards, but then our problem would be with the topmost message.
Expand Down

0 comments on commit 37b79bc

Please sign in to comment.