1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 00:58:50 -05:00

Split out deleteAttachment to avoid an extra SQL call if we can.

This commit is contained in:
Jesse Vincent 2010-08-29 16:56:45 +00:00
parent 38c31db8f6
commit 54a4c84afa

View File

@ -2261,6 +2261,47 @@ public class LocalStore extends Store implements Serializable
return PERMANENT_FLAGS;
}
private void deleteAttachments(long messageId) throws MessagingException
{
open(OpenMode.READ_WRITE);
Cursor attachmentsCursor = null;
try
{
attachmentsCursor = mDb.query(
"attachments",
new String[] { "id" },
"message_id = ?",
new String[] { Long.toString(messageId) },
null,
null,
null);
while (attachmentsCursor.moveToNext())
{
long attachmentId = attachmentsCursor.getLong(0);
try
{
File file = new File(mAttachmentsDir, Long.toString(attachmentId));
if (file.exists())
{
file.delete();
}
}
catch (Exception e)
{
}
}
}
finally
{
if (attachmentsCursor != null)
{
attachmentsCursor.close();
}
}
}
private void deleteAttachments(String uid) throws MessagingException
{
open(OpenMode.READ_WRITE);
@ -2278,41 +2319,8 @@ public class LocalStore extends Store implements Serializable
while (messagesCursor.moveToNext())
{
long messageId = messagesCursor.getLong(0);
Cursor attachmentsCursor = null;
try
{
attachmentsCursor = mDb.query(
"attachments",
new String[] { "id" },
"message_id = ?",
new String[] { Long.toString(messageId) },
null,
null,
null);
while (attachmentsCursor.moveToNext())
{
long attachmentId = attachmentsCursor.getLong(0);
try
{
File file = new File(mAttachmentsDir, Long.toString(attachmentId));
if (file.exists())
{
file.delete();
}
}
catch (Exception e)
{
deleteAttachments(messageId);
}
}
}
finally
{
if (attachmentsCursor != null)
{
attachmentsCursor.close();
}
}
}
}
finally