Removed transaction from search

This commit is contained in:
M66B 2021-02-28 16:48:51 +01:00
parent 6d196e8839
commit 14389f9efa
1 changed files with 92 additions and 109 deletions

View File

@ -141,6 +141,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
Log.i("Boundary run");
int found = 0; int found = 0;
try { try {
if (state.destroyed || state.error) if (state.destroyed || state.error)
@ -228,79 +230,68 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
return found; return found;
} }
try { while (found < pageSize && !state.destroyed) {
db.beginTransaction(); if (state.matches == null ||
(state.matches.size() > 0 && state.index >= state.matches.size())) {
while (found < pageSize && !state.destroyed) { state.matches = db.message().matchMessages(
if (state.matches == null || account, folder,
(state.matches.size() > 0 && state.index >= state.matches.size())) { criteria.query == null ? null : "%" + criteria.query + "%",
state.matches = db.message().matchMessages( criteria.in_senders,
account, folder, criteria.in_recipients,
criteria.query == null ? null : "%" + criteria.query + "%", criteria.in_subject,
criteria.in_senders, criteria.in_keywords,
criteria.in_recipients, criteria.in_message,
criteria.in_subject, criteria.in_notes,
criteria.in_keywords, criteria.with_unseen,
criteria.in_message, criteria.with_flagged,
criteria.in_notes, criteria.with_hidden,
criteria.with_unseen, criteria.with_encrypted,
criteria.with_flagged, criteria.with_attachments,
criteria.with_hidden, criteria.with_types == null ? 0 : criteria.with_types.length,
criteria.with_encrypted, criteria.with_types == null ? new String[]{} : criteria.with_types,
criteria.with_attachments, criteria.with_size,
criteria.with_types == null ? 0 : criteria.with_types.length, criteria.after,
criteria.with_types == null ? new String[]{} : criteria.with_types, criteria.before,
criteria.with_size, SEARCH_LIMIT_DEVICE, state.offset);
criteria.after, EntityLog.log(context, "Boundary device" +
criteria.before, " account=" + account +
SEARCH_LIMIT_DEVICE, state.offset); " folder=" + folder +
EntityLog.log(context, "Boundary device" + " criteria=" + criteria +
" account=" + account + " offset=" + state.offset +
" folder=" + folder + " size=" + state.matches.size());
" criteria=" + criteria + state.offset += Math.min(state.matches.size(), SEARCH_LIMIT_DEVICE);
" offset=" + state.offset + state.index = 0;
" size=" + state.matches.size());
state.offset += Math.min(state.matches.size(), SEARCH_LIMIT_DEVICE);
state.index = 0;
}
if (state.matches.size() == 0)
break;
for (int i = state.index; i < state.matches.size() && found < pageSize && !state.destroyed; i++) {
state.index = i + 1;
TupleMatch match = state.matches.get(i);
if (criteria.query != null &&
criteria.in_message &&
(match.matched == null || !match.matched))
try {
File file = EntityMessage.getFile(context, match.id);
if (file.exists()) {
String html = Helper.readText(file);
if (html.toLowerCase().contains(criteria.query)) {
String text = HtmlHelper.getFullText(html);
if (text.toLowerCase().contains(criteria.query))
match.matched = true;
}
}
} catch (IOException ex) {
Log.e(ex);
}
if (match.matched != null && match.matched) {
found++;
db.message().setMessageFound(match.id);
}
}
} }
db.setTransactionSuccessful(); if (state.matches.size() == 0)
break;
if (found == pageSize) for (int i = state.index; i < state.matches.size() && found < pageSize && !state.destroyed; i++) {
return found; state.index = i + 1;
} finally {
db.endTransaction(); TupleMatch match = state.matches.get(i);
if (criteria.query != null &&
criteria.in_message &&
(match.matched == null || !match.matched))
try {
File file = EntityMessage.getFile(context, match.id);
if (file.exists()) {
String html = Helper.readText(file);
if (html.toLowerCase().contains(criteria.query)) {
String text = HtmlHelper.getFullText(html);
if (text.toLowerCase().contains(criteria.query))
match.matched = true;
}
}
} catch (IOException ex) {
Log.e(ex);
}
if (match.matched != null && match.matched) {
found++;
db.message().setMessageFound(match.id);
}
}
} }
Log.i("Boundary device done"); Log.i("Boundary device done");
@ -491,46 +482,38 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
state.ifolder.fetch(add.toArray(new Message[0]), fp); state.ifolder.fetch(add.toArray(new Message[0]), fp);
} }
try { Core.State astate = new Core.State(ConnectionHelper.getNetworkState(context));
db.beginTransaction(); for (int j = isub.length - 1; j >= 0 && found < pageSize && !state.destroyed && astate.isRecoverable(); j--)
try {
Core.State astate = new Core.State(ConnectionHelper.getNetworkState(context)); long uid = state.ifolder.getUID(isub[j]);
for (int j = isub.length - 1; j >= 0 && found < pageSize && !state.destroyed && astate.isRecoverable(); j--) Log.i("Boundary server sync uid=" + uid);
try { EntityMessage message = db.message().getMessageByUid(browsable.id, uid);
long uid = state.ifolder.getUID(isub[j]); if (message == null) {
Log.i("Boundary server sync uid=" + uid); message = Core.synchronizeMessage(context,
EntityMessage message = db.message().getMessageByUid(browsable.id, uid); account, browsable,
if (message == null) { (IMAPStore) state.iservice.getStore(), state.ifolder, (MimeMessage) isub[j],
message = Core.synchronizeMessage(context, true, true,
account, browsable, rules, astate, null);
(IMAPStore) state.iservice.getStore(), state.ifolder, (MimeMessage) isub[j], found++;
true, true,
rules, astate, null);
found++;
}
if (message != null && criteria != null /* browsed */)
db.message().setMessageFound(message.id);
} catch (MessageRemovedException ex) {
Log.w(browsable.name + " boundary server", ex);
} catch (FolderClosedException ex) {
throw ex;
} catch (IOException ex) {
if (ex.getCause() instanceof MessagingException) {
Log.w(browsable.name + " boundary server", ex);
db.folder().setFolderError(browsable.id, Log.formatThrowable(ex));
} else
throw ex;
} catch (Throwable ex) {
Log.e(browsable.name + " boundary server", ex);
db.folder().setFolderError(browsable.id, Log.formatThrowable(ex));
} finally {
((IMAPMessage) isub[j]).invalidateHeaders();
} }
if (message != null && criteria != null /* browsed */)
db.setTransactionSuccessful(); db.message().setMessageFound(message.id);
} finally { } catch (MessageRemovedException ex) {
db.endTransaction(); Log.w(browsable.name + " boundary server", ex);
} } catch (FolderClosedException ex) {
throw ex;
} catch (IOException ex) {
if (ex.getCause() instanceof MessagingException) {
Log.w(browsable.name + " boundary server", ex);
db.folder().setFolderError(browsable.id, Log.formatThrowable(ex));
} else
throw ex;
} catch (Throwable ex) {
Log.e(browsable.name + " boundary server", ex);
db.folder().setFolderError(browsable.id, Log.formatThrowable(ex));
} finally {
((IMAPMessage) isub[j]).invalidateHeaders();
}
} }
if (state.index < 0) { if (state.index < 0) {