Quick fix for #1081 #1096
|
@ -2509,48 +2509,42 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
# self.rerenderInboxToLabels()
|
# self.rerenderInboxToLabels()
|
||||||
|
|
||||||
def on_action_MarkAllRead(self):
|
def on_action_MarkAllRead(self):
|
||||||
def partialUpdate(folder, msgids):
|
if QtGui.QMessageBox.question(
|
||||||
if len(msgids) == 0:
|
self, "Marking all messages as read?",
|
||||||
return 0
|
_translate(
|
||||||
if folder == 'sent':
|
"MainWindow",
|
||||||
return sqlExecute(
|
"Are you sure you would like to mark all messages read?"
|
||||||
"UPDATE sent SET read = 1 WHERE ackdata IN(%s) AND read=0" %(",".join("?"*len(msgids))), *msgids)
|
), QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
|
||||||
else:
|
|
||||||
return sqlExecute(
|
|
||||||
"UPDATE inbox SET read = 1 WHERE msgid IN(%s) AND read=0" %(",".join("?"*len(msgids))), *msgids)
|
|
||||||
|
|
||||||
if QtGui.QMessageBox.question(self, "Marking all messages as read?", _translate("MainWindow", "Are you sure you would like to mark all messages read?"), QMessageBox.Yes|QMessageBox.No) != QMessageBox.Yes:
|
|
||||||
return
|
return
|
||||||
addressAtCurrentRow = self.getCurrentAccount()
|
addressAtCurrentRow = self.getCurrentAccount()
|
||||||
tableWidget = self.getCurrentMessagelist()
|
tableWidget = self.getCurrentMessagelist()
|
||||||
|
|
||||||
if tableWidget.rowCount() == 0:
|
idCount = tableWidget.rowCount()
|
||||||
|
if idCount == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
msgids = []
|
|
||||||
|
|
||||||
font = QFont()
|
font = QFont()
|
||||||
font.setBold(False)
|
font.setBold(False)
|
||||||
|
|
||||||
markread = 0
|
msgids = []
|
||||||
|
for i in range(0, idCount):
|
||||||
for i in range(0, tableWidget.rowCount()):
|
|
||||||
msgids.append(str(tableWidget.item(
|
msgids.append(str(tableWidget.item(
|
||||||
i, 3).data(Qt.UserRole).toPyObject()))
|
i, 3).data(Qt.UserRole).toPyObject()))
|
||||||
tableWidget.item(i, 0).setUnread(False)
|
tableWidget.item(i, 0).setUnread(False)
|
||||||
tableWidget.item(i, 1).setUnread(False)
|
tableWidget.item(i, 1).setUnread(False)
|
||||||
tableWidget.item(i, 2).setUnread(False)
|
tableWidget.item(i, 2).setUnread(False)
|
||||||
tableWidget.item(i, 3).setFont(font)
|
tableWidget.item(i, 3).setFont(font)
|
||||||
# sqlite default limit, unfortunately getting/setting isn't exposed to python
|
|
||||||
if i % 999 == 999:
|
|
||||||
markread += partialUpdate(self.getCurrentFolder(), msgids)
|
|
||||||
msgids = []
|
|
||||||
|
|
||||||
if len(msgids) > 0:
|
markread = sqlExecuteChunked(
|
||||||
markread += partialUpdate(self.getCurrentFolder(), msgids)
|
"UPDATE %s SET read = 1 WHERE %s IN({0}) AND read=0" % (
|
||||||
|
('sent', 'ackdata') if self.getCurrentFolder() == 'sent'
|
||||||
|
else ('inbox', 'msgid')
|
||||||
|
), idCount, *msgids
|
||||||
|
)
|
||||||
|
|
||||||
if markread > 0:
|
if markread > 0:
|
||||||
self.propagateUnreadCount(addressAtCurrentRow, self.getCurrentFolder(), None, 0)
|
self.propagateUnreadCount(
|
||||||
|
addressAtCurrentRow, self.getCurrentFolder(), None, 0)
|
||||||
|
|
||||||
def click_NewAddressDialog(self):
|
def click_NewAddressDialog(self):
|
||||||
addresses = []
|
addresses = []
|
||||||
|
@ -2790,9 +2784,13 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
tableWidget.item(currentRow, 1).setUnread(True)
|
tableWidget.item(currentRow, 1).setUnread(True)
|
||||||
tableWidget.item(currentRow, 2).setUnread(True)
|
tableWidget.item(currentRow, 2).setUnread(True)
|
||||||
tableWidget.item(currentRow, 3).setFont(font)
|
tableWidget.item(currentRow, 3).setFont(font)
|
||||||
#sqlite requires the exact number of ?s to prevent injection
|
# for 1081
|
||||||
rowcount = sqlExecute('''UPDATE inbox SET read=0 WHERE msgid IN (%s) AND read=1''' % (
|
idCount = len(inventoryHashesToMarkUnread)
|
||||||
"?," * len(inventoryHashesToMarkUnread))[:-1], *inventoryHashesToMarkUnread)
|
rowcount = sqlExecuteChunked(
|
||||||
|
'''UPDATE inbox SET read=0 WHERE msgid IN ({0}) AND read=1''',
|
||||||
|
idCount, *inventoryHashesToMarkUnread
|
||||||
|
)
|
||||||
|
|
||||||
if rowcount == 1:
|
if rowcount == 1:
|
||||||
# performance optimisation
|
# performance optimisation
|
||||||
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), self.getCurrentFolder())
|
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), self.getCurrentFolder())
|
||||||
|
|
|
@ -21,8 +21,10 @@ def sqlQuery(sqlStatement, *args):
|
||||||
|
|
||||||
return queryreturn
|
return queryreturn
|
||||||
|
|
||||||
|
|
||||||
def sqlExecuteChunked(sqlStatement, idCount, *args):
|
def sqlExecuteChunked(sqlStatement, idCount, *args):
|
||||||
#SQLITE_MAX_VARIABLE_NUMBER, unfortunately getting/setting isn't exposed to python
|
# SQLITE_MAX_VARIABLE_NUMBER,
|
||||||
|
# unfortunately getting/setting isn't exposed to python
|
||||||
sqlExecuteChunked.chunkSize = 999
|
sqlExecuteChunked.chunkSize = 999
|
||||||
|
|
||||||
if idCount == 0 or idCount > len(args):
|
if idCount == 0 or idCount > len(args):
|
||||||
|
@ -30,15 +32,26 @@ def sqlExecuteChunked(sqlStatement, idCount, *args):
|
||||||
|
|
||||||
totalRowCount = 0
|
totalRowCount = 0
|
||||||
with sqlLock:
|
with sqlLock:
|
||||||
for i in range(len(args)-idCount, len(args), sqlExecuteChunked.chunkSize - (len(args)-idCount)):
|
for i in range(
|
||||||
sqlSubmitQueue.put(sqlStatement)
|
len(args) - idCount, len(args),
|
||||||
|
sqlExecuteChunked.chunkSize - (len(args) - idCount)
|
||||||
|
):
|
||||||
|
chunk_slice = args[
|
||||||
|
i:i+sqlExecuteChunked.chunkSize - (len(args) - idCount)
|
||||||
|
]
|
||||||
|
sqlSubmitQueue.put(
|
||||||
|
sqlStatement.format(','.join('?' * len(chunk_slice)))
|
||||||
|
)
|
||||||
# first static args, and then iterative chunk
|
# first static args, and then iterative chunk
|
||||||
sqlSubmitQueue.put(args[0:len(args)-idCount] + args[i:i+sqlExecuteChunked.chunkSize - (len(args)-idCount)])
|
sqlSubmitQueue.put(
|
||||||
|
args[0:len(args)-idCount] + chunk_slice
|
||||||
|
)
|
||||||
retVal = sqlReturnQueue.get()
|
retVal = sqlReturnQueue.get()
|
||||||
totalRowCount += retVal[1]
|
totalRowCount += retVal[1]
|
||||||
sqlSubmitQueue.put('commit')
|
sqlSubmitQueue.put('commit')
|
||||||
return totalRowCount
|
return totalRowCount
|
||||||
|
|
||||||
|
|
||||||
def sqlExecute(sqlStatement, *args):
|
def sqlExecute(sqlStatement, *args):
|
||||||
sqlLock.acquire()
|
sqlLock.acquire()
|
||||||
sqlSubmitQueue.put(sqlStatement)
|
sqlSubmitQueue.put(sqlStatement)
|
||||||
|
|
Reference in New Issue
Block a user