Simplified starting FTS indexing

This commit is contained in:
M66B 2020-01-15 12:07:45 +01:00
parent 7997ee74c5
commit 36e68347d0
8 changed files with 28 additions and 17 deletions

View File

@ -3042,6 +3042,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
EntityFolder drafts = db.folder().getFolderByType(message.account, EntityFolder.DRAFTS);
message.id = null;
message.folder = drafts.id;
message.fts = false;
message.ui_snoozed = null;
message.error = null;
message.id = db.message().insertMessage(message);

View File

@ -959,8 +959,6 @@ class Core {
int count = ifolder.getMessageCount();
db.folder().setFolderTotal(folder.id, count < 0 ? null : count);
}
WorkerFts.init(context, false);
}
private static void onDelete(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException {
@ -1988,8 +1986,6 @@ class Core {
Log.i(folder.name + " end sync state=" + state);
db.folder().setFolderSyncState(folder.id, null);
}
WorkerFts.init(context, false);
}
static EntityMessage synchronizeMessage(

View File

@ -499,10 +499,14 @@ public interface DaoMessage {
@Query("UPDATE message SET revisions = :revisions WHERE id = :id")
int setMessageRevisions(long id, Integer revisions);
@Query("UPDATE message SET content = :content WHERE id = :id")
@Query("UPDATE message" +
" SET content = :content, fts = 0" +
" WHERE id = :id")
int setMessageContent(long id, boolean content);
@Query("UPDATE message SET content = :content, plain_only = :plain_only, preview = :preview, warning = :warning WHERE id = :id")
@Query("UPDATE message" +
" SET content = :content, fts = 0, plain_only = :plain_only, preview = :preview, warning = :warning" +
" WHERE id = :id")
int setMessageContent(long id, boolean content, Boolean plain_only, String preview, String warning);
@Query("UPDATE message SET size = :size, total = :total WHERE id = :id")

View File

@ -101,14 +101,13 @@ public class EntityOperation {
jargs.put(value);
if (ADD.equals(name)) {
db.message().setMessageFts(message.id, false);
WorkerFts.init(context, false);
if (EntityMessage.PGP_SIGNENCRYPT.equals(message.encrypt) ||
EntityMessage.SMIME_SIGNENCRYPT.equals(message.encrypt)) {
EntityFolder folder = db.folder().getFolder(message.folder);
if (folder != null && EntityFolder.DRAFTS.equals(folder.type))
if (folder != null && EntityFolder.DRAFTS.equals(folder.type)) {
WorkerFts.init(context, false);
return;
}
}
}
@ -252,8 +251,6 @@ public class EntityOperation {
}
EntityAttachment.copy(context, message.id, tmpid);
WorkerFts.init(context, false);
}
// Cross account move

View File

@ -3649,6 +3649,7 @@ public class FragmentCompose extends FragmentBase {
draft.id = null;
draft.folder = db.folder().getOutbox().id;
draft.uid = null;
draft.fts = false;
draft.ui_hide = false;
draft.id = db.message().insertMessage(draft);
Helper.writeText(draft.getFile(context), body);

View File

@ -170,6 +170,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
});
liveAccountNetworkState.observeForever(new Observer<List<TupleAccountNetworkState>>() {
private boolean fts = false;
private List<TupleAccountNetworkState> accountStates = new ArrayList<>();
private ExecutorService queue = Helper.getBackgroundExecutor(1, "service");
@ -258,6 +259,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (lastAccounts != accounts || lastOperations != operations) {
lastAccounts = accounts;
lastOperations = operations;
if (operations == 0) {
fts = true;
WorkerFts.init(ServiceSynchronize.this, false);
} else if (fts) {
fts = false;
WorkerFts.cancel(ServiceSynchronize.this);
}
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(lastAccounts, lastOperations).build());
}

View File

@ -419,6 +419,7 @@ public class ServiceUI extends IntentService {
// A new message ID is needed for a new (wearable) notification
db.message().deleteMessage(id);
message.id = null;
message.fts = false;
message.id = db.message().insertMessage(message);
if (message.content)
EntityMessage.getFile(this, id)

View File

@ -96,17 +96,20 @@ public class WorkerFts extends Worker {
.enqueueUniqueWork(getName(), ExistingWorkPolicy.REPLACE, workRequest);
Log.i("Queued " + getName());
} else if (immediately) {
Log.i("Cancelling " + getName());
WorkManager.getInstance(context).cancelUniqueWork(getName());
Log.i("Cancelled " + getName());
}
} else if (immediately)
cancel(context);
} catch (IllegalStateException ex) {
// https://issuetracker.google.com/issues/138465476
Log.w(ex);
}
}
static void cancel(Context context) {
Log.i("Cancelling " + getName());
WorkManager.getInstance(context).cancelUniqueWork(getName());
Log.i("Cancelled " + getName());
}
private static String getName() {
return WorkerFts.class.getSimpleName();
}