Refactoring

pull/197/head
M66B 4 years ago
parent ccb026b7b2
commit 52b43e0d73

@ -249,7 +249,7 @@ public interface DaoMessage {
" JOIN folder_view AS folder ON folder.id = message.folder" +
" WHERE " + is_outbox +
" AND NOT ui_snoozed IS NULL")
LiveData<Integer> liveOutboxPending();
LiveData<Integer> liveOutboxPending();
@Query("SELECT account.name AS accountName" +
", COUNT(message.id) AS count" +
@ -310,13 +310,14 @@ public interface DaoMessage {
" ORDER BY message.received DESC")
List<Long> getMessageIdsByFolder(Long folder);
@Transaction
@Query("SELECT message.id FROM message" +
" JOIN folder_view AS folder ON folder.id = message.folder" +
" WHERE content" +
" AND NOT fts" +
" AND folder.type <> '" + EntityFolder.OUTBOX + "'" +
" ORDER BY message.received")
Cursor getMessageFts();
List<Long> getMessageFts();
@Query("SELECT message.id, account, thread, (:find IS NULL" +
" OR (:senders AND `from` LIKE :find COLLATE NOCASE)" + // no index

@ -21,7 +21,6 @@ package eu.faircode.email;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.text.TextUtils;
import androidx.annotation.NonNull;
@ -66,49 +65,47 @@ public class WorkerFts extends Worker {
SQLiteDatabase sdb = FtsDbHelper.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
try (Cursor cursor = db.message().getMessageFts()) {
while (cursor.moveToNext())
for (long id : db.message().getMessageFts())
try {
Log.i("FTS index=" + id);
ids.add(id);
EntityMessage message = db.message().getMessage(id);
if (message == null) {
Log.i("FTS gone");
continue;
}
File file = message.getFile(context);
String text = HtmlHelper.getFullText(file);
if (TextUtils.isEmpty(text)) {
Log.i("FTS empty");
continue;
}
boolean fts = prefs.getBoolean("fts", false);
if (!fts)
break;
try {
long id = cursor.getLong(0);
Log.i("FTS index=" + id);
ids.add(id);
EntityMessage message = db.message().getMessage(id);
if (message == null) {
Log.i("FTS gone");
continue;
}
File file = message.getFile(context);
String text = HtmlHelper.getFullText(file);
if (TextUtils.isEmpty(text)) {
Log.i("FTS empty");
continue;
}
boolean fts = prefs.getBoolean("fts", false);
if (!fts)
break;
try {
sdb.beginTransaction();
FtsDbHelper.insert(sdb, message, text);
sdb.setTransactionSuccessful();
} finally {
sdb.endTransaction();
}
indexed++;
if (ids.size() > INDEX_BATCH_SIZE)
markIndexed(db, ids);
} catch (Throwable ex) {
Log.e(ex);
sdb.beginTransaction();
FtsDbHelper.insert(sdb, message, text);
sdb.setTransactionSuccessful();
} finally {
sdb.endTransaction();
}
markIndexed(db, ids);
}
indexed++;
if (ids.size() > INDEX_BATCH_SIZE)
markIndexed(db, ids);
} catch (Throwable ex) {
Log.e(ex);
}
markIndexed(db, ids);
Log.i("FTS indexed=" + indexed);
return Result.success();

Loading…
Cancel
Save