mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-23 14:41:08 +00:00
Improved search performance
This commit is contained in:
parent
0d25268240
commit
1772530ae6
5 changed files with 61 additions and 28 deletions
|
@ -281,7 +281,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
|||
|
||||
int applied = 0;
|
||||
List<Long> ids =
|
||||
db.message().getMessageIdsByFolder(rule.folder, null, null, null);
|
||||
db.message().getMessageIdsByFolder(rule.folder);
|
||||
for (long mid : ids)
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
|
|
@ -176,46 +176,44 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
|
||||
}
|
||||
|
||||
if (state.messages == null) {
|
||||
state.messages = db.message().getMessageIdsByFolder(folder, seen, flagged, snoozed);
|
||||
if (state.matches == null) {
|
||||
state.matches = db.message().matchMessages(folder, find, seen, flagged, snoozed);
|
||||
Log.i("Boundary device folder=" + folder +
|
||||
" query=" + query +
|
||||
" seen=" + seen +
|
||||
" flagged=" + flagged +
|
||||
" snoozed=" + snoozed +
|
||||
" messages=" + state.messages.size());
|
||||
" matches=" + state.matches.size());
|
||||
}
|
||||
|
||||
int found = 0;
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
for (int i = state.index; i < state.messages.size() && found < pageSize && !state.destroyed; i++) {
|
||||
for (int i = state.index; i < state.matches.size() && found < pageSize && !state.destroyed; i++) {
|
||||
state.index = i + 1;
|
||||
|
||||
long id = state.messages.get(i);
|
||||
EntityMessage message;
|
||||
TupleMatch match = state.matches.get(i);
|
||||
|
||||
if (find == null || seen != null || flagged != null || snoozed != null)
|
||||
message = db.message().getMessage(id);
|
||||
match.matched = true;
|
||||
else {
|
||||
message = db.message().match(id, "%" + find + "%");
|
||||
if (message == null)
|
||||
if (match.matched == null || !match.matched)
|
||||
try {
|
||||
File file = EntityMessage.getFile(context, id);
|
||||
File file = EntityMessage.getFile(context, match.id);
|
||||
if (file.exists()) {
|
||||
String body = Helper.readText(file);
|
||||
if (body.toLowerCase(Locale.ROOT).contains(find))
|
||||
message = db.message().getMessage(id);
|
||||
match.matched = true;
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (message != null) {
|
||||
if (match.matched != null && match.matched) {
|
||||
found++;
|
||||
db.message().setMessageFound(message.account, message.thread);
|
||||
db.message().setMessageFound(match.account, match.thread);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -515,7 +513,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
boolean destroyed = false;
|
||||
boolean error = false;
|
||||
int index = 0;
|
||||
List<Long> messages = null;
|
||||
List<TupleMatch> matches = null;
|
||||
|
||||
MailService iservice = null;
|
||||
IMAPFolder ifolder = null;
|
||||
|
|
|
@ -212,6 +212,19 @@ public interface DaoMessage {
|
|||
List<Long> getMessageByFolder(long folder);
|
||||
|
||||
@Query("SELECT id" +
|
||||
" FROM message" +
|
||||
" WHERE (:folder IS NULL OR folder = :folder)" +
|
||||
" AND NOT ui_hide" +
|
||||
" ORDER BY message.received DESC")
|
||||
List<Long> getMessageIdsByFolder(Long folder);
|
||||
|
||||
@Query("SELECT id, account, thread, (:find IS NULL" +
|
||||
" OR `from` LIKE :find COLLATE NOCASE" +
|
||||
" OR `to` LIKE :find COLLATE NOCASE" +
|
||||
" OR `cc` LIKE :find COLLATE NOCASE" +
|
||||
" OR `subject` LIKE :find COLLATE NOCASE" +
|
||||
" OR `keywords` LIKE :find COLLATE NOCASE" +
|
||||
" OR `preview` LIKE :find COLLATE NOCASE) AS matched" +
|
||||
" FROM message" +
|
||||
" WHERE (:folder IS NULL OR folder = :folder)" +
|
||||
" AND NOT ui_hide" +
|
||||
|
@ -222,7 +235,7 @@ public interface DaoMessage {
|
|||
" WHEN 1 THEN message.ui_snoozed IS NOT NULL" +
|
||||
" ELSE 1 END" + // NULL: true
|
||||
" ORDER BY message.received DESC")
|
||||
List<Long> getMessageIdsByFolder(Long folder, Boolean seen, Boolean flagged, Boolean snoozed);
|
||||
List<TupleMatch> matchMessages(Long folder, String find, Boolean seen, Boolean flagged, Boolean snoozed);
|
||||
|
||||
@Query("SELECT id" +
|
||||
" FROM message" +
|
||||
|
@ -364,16 +377,6 @@ public interface DaoMessage {
|
|||
" ORDER BY sender, subject")
|
||||
Cursor getSuggestions(String query);
|
||||
|
||||
@Query("SELECT * FROM message" +
|
||||
" WHERE id = :id" +
|
||||
" AND (`from` LIKE :find COLLATE NOCASE" +
|
||||
" OR `to` LIKE :find COLLATE NOCASE" +
|
||||
" OR `cc` LIKE :find COLLATE NOCASE" +
|
||||
" OR `subject` LIKE :find COLLATE NOCASE" +
|
||||
" OR `keywords` LIKE :find COLLATE NOCASE" +
|
||||
" OR `preview` LIKE :find COLLATE NOCASE)")
|
||||
EntityMessage match(long id, String find);
|
||||
|
||||
@Insert
|
||||
long insertMessage(EntityMessage message);
|
||||
|
||||
|
|
|
@ -1111,7 +1111,7 @@ public class FragmentRule extends FragmentBase {
|
|||
|
||||
DB db = DB.getInstance(context);
|
||||
List<Long> ids =
|
||||
db.message().getMessageIdsByFolder(rule.folder, null, null, null);
|
||||
db.message().getMessageIdsByFolder(rule.folder);
|
||||
for (long mid : ids)
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
@ -1157,7 +1157,7 @@ public class FragmentRule extends FragmentBase {
|
|||
|
||||
DB db = DB.getInstance(context);
|
||||
List<Long> ids =
|
||||
db.message().getMessageIdsByFolder(rule.folder, null, null, null);
|
||||
db.message().getMessageIdsByFolder(rule.folder);
|
||||
for (long id : ids) {
|
||||
EntityMessage message = db.message().getMessage(id);
|
||||
if (message == null)
|
||||
|
|
32
app/src/main/java/eu/faircode/email/TupleMatch.java
Normal file
32
app/src/main/java/eu/faircode/email/TupleMatch.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FairEmail is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class TupleMatch {
|
||||
@NonNull
|
||||
public Long id;
|
||||
@NonNull
|
||||
public Long account;
|
||||
@NonNull
|
||||
public String thread;
|
||||
public Boolean matched;
|
||||
}
|
Loading…
Reference in a new issue