Search cleanup

pull/183/head
M66B 5 years ago
parent 310349ed53
commit f9586534ae

@ -91,7 +91,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
private State state; private State state;
private static final int SEARCH_LIMIT_DEVICE = 1000; private static final int SEARCH_LIMIT_DEVICE = 1000;
private static final int SEARCH_LIMIT_SERVER = 100; private static final int SEARCH_LIMIT_SERVER = 250;
private static ExecutorService executor = Helper.getBackgroundExecutor(1, "boundary"); private static ExecutorService executor = Helper.getBackgroundExecutor(1, "boundary");
interface IBoundaryCallbackMessages { interface IBoundaryCallbackMessages {
@ -209,7 +209,6 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
" folder=" + folder + " folder=" + folder +
" criteria=" + criteria + " criteria=" + criteria +
" ids=" + state.ids.size()); " ids=" + state.ids.size());
EntityLog.log(context, "FTS results=" + state.ids.size());
} }
try { try {
@ -423,27 +422,24 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
} }
} catch (Throwable ex) { } catch (Throwable ex) {
ProtocolException pex = new ProtocolException( ProtocolException pex = new ProtocolException(
"Search " + account.host + " " + criteria, ex); "Search " + account.host, ex);
EntityLog.log(context, pex.toString()); Log.e(pex);
//Log.e(pex);
throw pex; throw pex;
} }
} }
}); });
state.imessages = (Message[]) result; state.imessages = (Message[]) result;
EntityLog.log(context, "Boundary found messages=" + state.imessages.length);
} }
Log.i("Boundary server found messages=" + state.imessages.length); EntityLog.log(context, "Boundary found messages=" + state.imessages.length);
state.index = state.imessages.length - 1; state.index = state.imessages.length - 1;
} catch (Throwable ex) { } catch (Throwable ex) {
state.error = true; state.error = true;
EntityLog.log(context, ex.toString()); if (ex instanceof FolderClosedException)
//if (ex instanceof FolderClosedException) Log.w("Search", ex);
// Log.w("Search", ex); else
//else Log.e("Search", ex);
// Log.e("Search", ex);
throw ex; throw ex;
} }
@ -451,7 +447,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
int found = 0; int found = 0;
while (state.index >= 0 && found < pageSize && !state.destroyed) { while (state.index >= 0 && found < pageSize && !state.destroyed) {
EntityLog.log(context, "Boundary server index=" + state.index); Log.i("Boundary server index=" + state.index);
int from = Math.max(0, state.index - (pageSize - found) + 1); int from = Math.max(0, state.index - (pageSize - found) + 1);
Message[] isub = Arrays.copyOfRange(state.imessages, from, state.index + 1); Message[] isub = Arrays.copyOfRange(state.imessages, from, state.index + 1);
state.index -= (pageSize - found); state.index -= (pageSize - found);
@ -471,7 +467,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
add.add(m); add.add(m);
} }
EntityLog.log(context, "Boundary fetching " + add.size() + "/" + isub.length); Log.i("Boundary fetching " + add.size() + "/" + isub.length);
if (add.size() > 0) { if (add.size() > 0) {
FetchProfile fp = new FetchProfile(); FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE); fp.add(FetchProfile.Item.ENVELOPE);
@ -496,7 +492,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
for (int j = isub.length - 1; j >= 0 && found < pageSize && !state.destroyed && astate.isRecoverable(); j--) for (int j = isub.length - 1; j >= 0 && found < pageSize && !state.destroyed && astate.isRecoverable(); j--)
try { try {
long uid = state.ifolder.getUID(isub[j]); long uid = state.ifolder.getUID(isub[j]);
EntityLog.log(context, "Boundary server sync index=" + state.index + " j=" + j + " uid=" + uid); Log.i("Boundary server sync uid=" + uid);
EntityMessage message = db.message().getMessageByUid(browsable.id, uid); EntityMessage message = db.message().getMessageByUid(browsable.id, uid);
if (message == null) { if (message == null) {
message = Core.synchronizeMessage(context, message = Core.synchronizeMessage(context,
@ -506,26 +502,19 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
rules, astate); rules, astate);
found++; found++;
} }
if (message != null && criteria != null /* browsed */) { if (message != null && criteria != null /* browsed */)
EntityLog.log(context, "Boundary server found uid=" + uid);
db.message().setMessageFound(message.id); db.message().setMessageFound(message.id);
} else
EntityLog.log(context, "Boundary server browsed uid=" + uid);
} catch (MessageRemovedException ex) { } catch (MessageRemovedException ex) {
EntityLog.log(context, browsable.name + " boundary server ex=" + ex);
Log.w(browsable.name + " boundary server", ex); Log.w(browsable.name + " boundary server", ex);
} catch (FolderClosedException ex) { } catch (FolderClosedException ex) {
EntityLog.log(context, browsable.name + " boundary server ex=" + ex);
throw ex; throw ex;
} catch (IOException ex) { } catch (IOException ex) {
EntityLog.log(context, browsable.name + " boundary server ex=" + ex);
if (ex.getCause() instanceof MessagingException) { if (ex.getCause() instanceof MessagingException) {
Log.w(browsable.name + " boundary server", ex); Log.w(browsable.name + " boundary server", ex);
db.folder().setFolderError(browsable.id, Log.formatThrowable(ex)); db.folder().setFolderError(browsable.id, Log.formatThrowable(ex));
} else } else
throw ex; throw ex;
} catch (Throwable ex) { } catch (Throwable ex) {
EntityLog.log(context, browsable.name + " boundary server ex=" + ex);
Log.e(browsable.name + " boundary server", ex); Log.e(browsable.name + " boundary server", ex);
db.folder().setFolderError(browsable.id, Log.formatThrowable(ex)); db.folder().setFolderError(browsable.id, Log.formatThrowable(ex));
} finally { } finally {
@ -538,7 +527,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
} }
} }
EntityLog.log(context, "Boundary server done"); Log.i("Boundary server done");
return found; return found;
} }
@ -546,10 +535,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
EntityLog.log(context, "Search utf8=" + utf8); EntityLog.log(context, "Search utf8=" + utf8);
SearchTerm terms = criteria.getTerms(utf8, state.ifolder.getPermanentFlags(), keywords); SearchTerm terms = criteria.getTerms(utf8, state.ifolder.getPermanentFlags(), keywords);
if (terms == null) { if (terms == null)
EntityLog.log(context, "Search no terms"); throw new ProtocolException("No search conditions");
return new Message[0];
}
SearchSequence ss = new SearchSequence(protocol); SearchSequence ss = new SearchSequence(protocol);
Argument args = ss.generateSequence(terms, utf8 ? StandardCharsets.UTF_8.name() : null); Argument args = ss.generateSequence(terms, utf8 ? StandardCharsets.UTF_8.name() : null);
@ -557,9 +544,9 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
Response[] responses = protocol.command("SEARCH", args); // no CHARSET ! Response[] responses = protocol.command("SEARCH", args); // no CHARSET !
if (responses == null || responses.length == 0) if (responses == null || responses.length == 0)
throw new ProtocolException("No response"); throw new ProtocolException("No response from server");
for (Response response : responses) for (Response response : responses)
EntityLog.log(context, "Search response=" + response); Log.i("Search response=" + response);
if (!responses[responses.length - 1].isOK()) if (!responses[responses.length - 1].isOK())
throw new ProtocolException(responses[responses.length - 1]); throw new ProtocolException(responses[responses.length - 1]);

Loading…
Cancel
Save