Moved folder I/O before database transaction

pull/156/head
M66B 6 years ago
parent 910a7a1f5d
commit a6cb93fc47

@ -687,45 +687,51 @@ class Core {
static void onSynchronizeFolders(Context context, EntityAccount account, Store istore, State state) throws MessagingException { static void onSynchronizeFolders(Context context, EntityAccount account, Store istore, State state) throws MessagingException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try {
Log.i("Start sync folders account=" + account.name);
// Get remote folders Log.i("Start sync folders account=" + account.name);
Folder defaultFolder = istore.getDefaultFolder();
char separator = defaultFolder.getSeparator();
EntityLog.log(context, account.name + " folder separator=" + separator);
Folder[] ifolders = defaultFolder.list("*"); // Get remote folders
Map<Folder, String[]> attrs = new HashMap<>(); Folder defaultFolder = istore.getDefaultFolder();
for (Folder ifolder : ifolders) char separator = defaultFolder.getSeparator();
attrs.put(ifolder, ((IMAPFolder) ifolder).getAttributes()); EntityLog.log(context, account.name + " folder separator=" + separator);
Log.i("Remote folder count=" + ifolders.length + " separator=" + separator);
db.beginTransaction(); // Get remote folder attributes
Folder[] ifolders = defaultFolder.list("*");
Map<Folder, String[]> attrs = new HashMap<>();
Map<Folder, Boolean> subscribed = new HashMap<>();
for (Folder ifolder : ifolders) {
subscribed.put(ifolder, ifolder.isSubscribed());
attrs.put(ifolder, ((IMAPFolder) ifolder).getAttributes());
}
Log.i("Remote folder count=" + ifolders.length + " separator=" + separator);
// Get folder names
List<String> names = new ArrayList<>();
for (EntityFolder folder : db.folder().getFolders(account.id))
if (folder.tbc != null) {
Log.i(folder.name + " creating");
Folder ifolder = istore.getFolder(folder.name);
if (!ifolder.exists())
ifolder.create(Folder.HOLDS_MESSAGES);
db.folder().resetFolderTbc(folder.id);
names.add(folder.name);
} else if (folder.tbd != null && folder.tbd) {
Log.i(folder.name + " deleting");
Folder ifolder = istore.getFolder(folder.name);
if (ifolder.exists())
ifolder.delete(false);
db.folder().deleteFolder(folder.id);
} else
names.add(folder.name);
Log.i("Local folder count=" + names.size());
List<String> names = new ArrayList<>(); try {
for (EntityFolder folder : db.folder().getFolders(account.id)) db.beginTransaction();
if (folder.tbc != null) {
Log.i(folder.name + " creating");
Folder ifolder = istore.getFolder(folder.name);
if (!ifolder.exists())
ifolder.create(Folder.HOLDS_MESSAGES);
db.folder().resetFolderTbc(folder.id);
} else if (folder.tbd != null && folder.tbd) {
Log.i(folder.name + " deleting");
Folder ifolder = istore.getFolder(folder.name);
if (ifolder.exists())
ifolder.delete(false);
db.folder().deleteFolder(folder.id);
} else
names.add(folder.name);
Log.i("Local folder count=" + names.size());
Map<String, EntityFolder> nameFolder = new HashMap<>(); Map<String, EntityFolder> nameFolder = new HashMap<>();
Map<String, List<EntityFolder>> parentFolders = new HashMap<>(); Map<String, List<EntityFolder>> parentFolders = new HashMap<>();
for (Folder ifolder : ifolders) { for (Folder ifolder : ifolders) {
String fullName = ifolder.getFullName(); String fullName = ifolder.getFullName(); // No I/O
boolean subscribed = ifolder.isSubscribed();
String[] attr = attrs.get(ifolder); String[] attr = attrs.get(ifolder);
String type = EntityFolder.getType(attr, fullName); String type = EntityFolder.getType(attr, fullName);
@ -747,7 +753,7 @@ class Core {
folder.display = display; folder.display = display;
folder.type = (EntityFolder.SYSTEM.equals(type) ? type : EntityFolder.USER); folder.type = (EntityFolder.SYSTEM.equals(type) ? type : EntityFolder.USER);
folder.synchronize = false; folder.synchronize = false;
folder.subscribed = subscribed; folder.subscribed = subscribed.get(ifolder);
folder.poll = ("imap.gmail.com".equals(account.host)); folder.poll = ("imap.gmail.com".equals(account.host));
folder.sync_days = EntityFolder.DEFAULT_SYNC; folder.sync_days = EntityFolder.DEFAULT_SYNC;
folder.keep_days = EntityFolder.DEFAULT_KEEP; folder.keep_days = EntityFolder.DEFAULT_KEEP;
@ -757,7 +763,7 @@ class Core {
Log.i(folder.name + " exists type=" + folder.type); Log.i(folder.name + " exists type=" + folder.type);
if (folder.subscribed == null || !folder.subscribed.equals(subscribed)) if (folder.subscribed == null || !folder.subscribed.equals(subscribed))
db.folder().setFolderSubscribed(folder.id, subscribed); db.folder().setFolderSubscribed(folder.id, subscribed.get(ifolder));
if (folder.display == null) { if (folder.display == null) {
if (display != null) { if (display != null) {

Loading…
Cancel
Save