IMAP: reduce quickchanged() checks
For each folder we were making a second IMAP request asking for the latest UID and compared that with the highest UID in our statusfolder. This catched the case that 1 mail has been deleted by someone else and another one has arrived since we checked, so that the total number of mails appears to not have changed. We don't capture anymore this case in the quickchanged() case. It improves my performance from 8 to about 7.5 seconds per check (with lots of variation) and we would benefit even more in the IMAP<->IMAP case as we do one additional IMAP lookup per folder on each side then. Do cleanups on whitespaces while in this file. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
12e11429b5
commit
36eb37b47d
@ -74,7 +74,7 @@ class IMAPFolder(BaseFolder):
|
|||||||
return long(imapobj._get_untagged_response('UIDVALIDITY', True)[0])
|
return long(imapobj._get_untagged_response('UIDVALIDITY', True)[0])
|
||||||
finally:
|
finally:
|
||||||
self.imapserver.releaseconnection(imapobj)
|
self.imapserver.releaseconnection(imapobj)
|
||||||
|
|
||||||
def quickchanged(self, statusfolder):
|
def quickchanged(self, statusfolder):
|
||||||
# An IMAP folder has definitely changed if the number of
|
# An IMAP folder has definitely changed if the number of
|
||||||
# messages or the UID of the last message have changed. Otherwise
|
# messages or the UID of the last message have changed. Otherwise
|
||||||
@ -97,26 +97,8 @@ class IMAPFolder(BaseFolder):
|
|||||||
if maxmsgid != statusfolder.getmessagecount():
|
if maxmsgid != statusfolder.getmessagecount():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if maxmsgid < 1:
|
|
||||||
# No messages; return
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Now, get the UID for the last message.
|
|
||||||
response = imapobj.fetch('%d' % maxmsgid, '(UID)')[1]
|
|
||||||
finally:
|
finally:
|
||||||
self.imapserver.releaseconnection(imapobj)
|
self.imapserver.releaseconnection(imapobj)
|
||||||
|
|
||||||
# Discard the message number.
|
|
||||||
messagestr = response[0].split(' ', 1)[1]
|
|
||||||
options = imaputil.flags2hash(messagestr)
|
|
||||||
if not options.has_key('UID'):
|
|
||||||
return True
|
|
||||||
uid = long(options['UID'])
|
|
||||||
saveduids = statusfolder.getmessageuidlist()
|
|
||||||
saveduids.sort()
|
|
||||||
if uid != saveduids[-1]:
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# TODO: Make this so that it can define a date that would be the oldest messages etc.
|
# TODO: Make this so that it can define a date that would be the oldest messages etc.
|
||||||
@ -216,13 +198,13 @@ class IMAPFolder(BaseFolder):
|
|||||||
self.ui.debug('imap', 'Returned object from fetching %d: %s' % \
|
self.ui.debug('imap', 'Returned object from fetching %d: %s' % \
|
||||||
(uid, str(initialresult)))
|
(uid, str(initialresult)))
|
||||||
return initialresult[1][0][1].replace("\r\n", "\n")
|
return initialresult[1][0][1].replace("\r\n", "\n")
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
self.imapserver.releaseconnection(imapobj)
|
self.imapserver.releaseconnection(imapobj)
|
||||||
|
|
||||||
def getmessagetime(self, uid):
|
def getmessagetime(self, uid):
|
||||||
return self.messagelist[uid]['time']
|
return self.messagelist[uid]['time']
|
||||||
|
|
||||||
def getmessageflags(self, uid):
|
def getmessageflags(self, uid):
|
||||||
return self.messagelist[uid]['flags']
|
return self.messagelist[uid]['flags']
|
||||||
|
|
||||||
@ -416,16 +398,16 @@ class IMAPFolder(BaseFolder):
|
|||||||
# get the date of the message file, so we can pass it to the server.
|
# get the date of the message file, so we can pass it to the server.
|
||||||
date = self.getmessageinternaldate(content, rtime)
|
date = self.getmessageinternaldate(content, rtime)
|
||||||
self.ui.debug('imap', 'savemessage: using date %s' % date)
|
self.ui.debug('imap', 'savemessage: using date %s' % date)
|
||||||
|
|
||||||
content = re.sub("(?<!\r)\n", "\r\n", content)
|
content = re.sub("(?<!\r)\n", "\r\n", content)
|
||||||
|
|
||||||
if not use_uidplus:
|
if not use_uidplus:
|
||||||
# insert a random unique header that we can fetch later
|
# insert a random unique header that we can fetch later
|
||||||
(headername, headervalue) = self.generate_randomheader(content)
|
(headername, headervalue) = self.generate_randomheader(content)
|
||||||
self.ui.debug('imap', 'savemessage: new headers are: %s: %s' % \
|
self.ui.debug('imap', 'savemessage: new headers are: %s: %s' % \
|
||||||
(headername, headervalue))
|
(headername, headervalue))
|
||||||
content = self.savemessage_addheader(content, headername,
|
content = self.savemessage_addheader(content, headername,
|
||||||
headervalue)
|
headervalue)
|
||||||
self.ui.debug('imap', 'savemessage: content is: ' + repr(content))
|
self.ui.debug('imap', 'savemessage: content is: ' + repr(content))
|
||||||
|
|
||||||
# TODO: - append could raise a ValueError if the date is not in
|
# TODO: - append could raise a ValueError if the date is not in
|
||||||
@ -516,7 +498,7 @@ class IMAPFolder(BaseFolder):
|
|||||||
self.processmessagesflags(operation, uidlist[:100], flags)
|
self.processmessagesflags(operation, uidlist[:100], flags)
|
||||||
self.processmessagesflags(operation, uidlist[100:], flags)
|
self.processmessagesflags(operation, uidlist[100:], flags)
|
||||||
return
|
return
|
||||||
|
|
||||||
imapobj = self.imapserver.acquireconnection()
|
imapobj = self.imapserver.acquireconnection()
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
@ -573,7 +555,7 @@ class IMAPFolder(BaseFolder):
|
|||||||
# Weed out ones not in self.messagelist
|
# Weed out ones not in self.messagelist
|
||||||
uidlist = [uid for uid in uidlist if uid in self.messagelist]
|
uidlist = [uid for uid in uidlist if uid in self.messagelist]
|
||||||
if not len(uidlist):
|
if not len(uidlist):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.addmessagesflags_noconvert(uidlist, ['T'])
|
self.addmessagesflags_noconvert(uidlist, ['T'])
|
||||||
imapobj = self.imapserver.acquireconnection()
|
imapobj = self.imapserver.acquireconnection()
|
||||||
@ -589,5 +571,5 @@ class IMAPFolder(BaseFolder):
|
|||||||
self.imapserver.releaseconnection(imapobj)
|
self.imapserver.releaseconnection(imapobj)
|
||||||
for uid in uidlist:
|
for uid in uidlist:
|
||||||
del self.messagelist[uid]
|
del self.messagelist[uid]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user