Optimise UI deleting and undeleting multiple messages

- use sqlExecuteChunked and disable UI updates while removing entries
This commit is contained in:
Peter Šurda 2018-01-28 08:12:46 +01:00
parent bc7227f513
commit 0f61ed9f19
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -2985,54 +2985,61 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()
if not tableWidget: if not tableWidget:
return return
unread = False
currentRow = 0 currentRow = 0
folder = self.getCurrentFolder() folder = self.getCurrentFolder()
shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier
while tableWidget.selectedIndexes(): tableWidget.setUpdatesEnabled(False);
currentRow = tableWidget.selectedIndexes()[0].row() inventoryHashesToTrash = []
for row in tableWidget.selectedIndexes():
currentRow = row.row()
inventoryHashToTrash = str(tableWidget.item( inventoryHashToTrash = str(tableWidget.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
if folder == "trash" or shifted: if inventoryHashToTrash in inventoryHashesToTrash:
sqlExecute('''DELETE FROM inbox WHERE msgid=?''', inventoryHashToTrash) continue
else: inventoryHashesToTrash.append(inventoryHashToTrash)
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash)
if tableWidget.item(currentRow, 0).unread:
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), folder, self.getCurrentTreeWidget(), -1)
if folder != "trash" and not shifted:
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), "trash", self.getCurrentTreeWidget(), 1)
self.getCurrentMessageTextedit().setText("")
tableWidget.removeRow(currentRow) tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate( idCount = len(inventoryHashesToTrash)
"MainWindow", "Moved items to trash."), 10000) if folder == "trash" or shifted:
if currentRow == 0: sqlExecuteChunked('''DELETE FROM inbox WHERE msgid IN ({0})''',
tableWidget.selectRow(currentRow) idCount, *inventoryHashesToTrash)
else: else:
tableWidget.selectRow(currentRow - 1) sqlExecuteChunked('''UPDATE inbox SET folder='trash' WHERE msgid IN ({0})''',
idCount, *inventoryHashesToTrash)
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
self.getCurrentMessageTextedit().setText("")
tableWidget.setUpdatesEnabled(True)
self.propagateUnreadCount(self.getCurrentAccount, folder)
self.statusBar().showMessage(_translate(
"MainWindow", "Moved items to trash."), 10000)
def on_action_TrashUndelete(self): def on_action_TrashUndelete(self):
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()
if not tableWidget: if not tableWidget:
return return
unread = False
currentRow = 0 currentRow = 0
while tableWidget.selectedIndexes(): tableWidget.setUpdatesEnabled(False)
currentRow = tableWidget.selectedIndexes()[0].row() inventoryHashesToTrash = []
for row in tableWidget.selectedIndexes():
currentRow = row.row()
inventoryHashToTrash = str(tableWidget.item( inventoryHashToTrash = str(tableWidget.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
sqlExecute('''UPDATE inbox SET folder='inbox' WHERE msgid=?''', inventoryHashToTrash) if inventoryHashToTrash in inventoryHashesToTrash:
if tableWidget.item(currentRow, 0).unread: continue
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), "inbox", self.getCurrentTreeWidget(), 1) inventoryHashesToTrash.append(inventoryHashToTrash)
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), "trash", self.getCurrentTreeWidget(), -1)
self.getCurrentMessageTextedit().setText("")
tableWidget.removeRow(currentRow) tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate(
"MainWindow", "Undeleted item."), 10000)
if currentRow == 0: if currentRow == 0:
tableWidget.selectRow(currentRow) tableWidget.selectRow(currentRow)
else: else:
tableWidget.selectRow(currentRow - 1) tableWidget.selectRow(currentRow - 1)
idCount = len(inventoryHashesToTrash)
sqlExecuteChunked('''UPDATE inbox SET folder='inbox' WHERE msgid IN({0})''',
idCount, *inventoryHashesToTrash)
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
self.getCurrentMessageTextedit().setText("")
tableWidget.setUpdatesEnabled(True)
self.propagateUnreadCount(self.getCurrentAccount)
self.statusBar().showMessage(_translate(
"MainWindow", "Undeleted items."), 10000)
def on_action_InboxSaveMessageAs(self): def on_action_InboxSaveMessageAs(self):
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()