mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 21:15:48 +00:00
Prevent thread trimming from gumming up the database.
This commit is contained in:
@@ -3322,24 +3322,18 @@ public class MessageTable extends DatabaseTable implements MessageTypes, Recipie
|
||||
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
|
||||
String where = THREAD_ID + " = ? AND " + DATE_RECEIVED + " < " + date;
|
||||
|
||||
int count = db.delete(TABLE_NAME, where, SqlUtil.buildArgs(threadId));
|
||||
|
||||
if (count > 0) {
|
||||
OptimizeMessageSearchIndexJob.enqueue();
|
||||
}
|
||||
|
||||
return count;
|
||||
return db.delete(TABLE_NAME, where, SqlUtil.buildArgs(threadId));
|
||||
}
|
||||
|
||||
void deleteAbandonedMessages() {
|
||||
int deleteAbandonedMessages() {
|
||||
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
|
||||
String where = THREAD_ID + " NOT IN (SELECT _id FROM " + ThreadTable.TABLE_NAME + ")";
|
||||
|
||||
int deletes = db.delete(TABLE_NAME, where, null);
|
||||
if (deletes > 0) {
|
||||
Log.i(TAG, "Deleted " + deletes + " abandoned messages");
|
||||
OptimizeMessageSearchIndexJob.enqueue();
|
||||
}
|
||||
return deletes;
|
||||
}
|
||||
|
||||
public void deleteRemotelyDeletedStory(long messageId) {
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList
|
||||
import org.thoughtcrime.securesms.database.model.serialize
|
||||
import org.thoughtcrime.securesms.groups.BadGroupIdException
|
||||
import org.thoughtcrime.securesms.groups.GroupId
|
||||
import org.thoughtcrime.securesms.jobs.OptimizeMessageSearchIndexJob
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.mms.SlideDeck
|
||||
import org.thoughtcrime.securesms.mms.StickerSlide
|
||||
@@ -311,6 +312,7 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||
|
||||
notifyAttachmentListeners()
|
||||
notifyStickerPackListeners()
|
||||
OptimizeMessageSearchIndexJob.enqueue()
|
||||
}
|
||||
|
||||
fun trimThread(threadId: Long, length: Int, trimBeforeDate: Long) {
|
||||
@@ -333,6 +335,7 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||
|
||||
notifyAttachmentListeners()
|
||||
notifyStickerPackListeners()
|
||||
OptimizeMessageSearchIndexJob.enqueue()
|
||||
}
|
||||
|
||||
private fun trimThreadInternal(threadId: Long, length: Int, trimBeforeDate: Long) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.signal.core.util.ThreadUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.DefaultExecutorFactory;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.JsonDataSerializer;
|
||||
import org.thoughtcrime.securesms.jobmanager.persistence.JobSpec;
|
||||
@@ -60,7 +61,12 @@ public class JobManager implements ConstraintObserver.Notifier {
|
||||
public JobManager(@NonNull Application application, @NonNull Configuration configuration) {
|
||||
this.application = application;
|
||||
this.configuration = configuration;
|
||||
this.executor = ThreadUtil.trace(new FilteredExecutor(configuration.getExecutorFactory().newSingleThreadExecutor("signal-JobManager"), ThreadUtil::isMainThread));
|
||||
this.executor = ThreadUtil.trace(new FilteredExecutor(configuration.getExecutorFactory().newSingleThreadExecutor("signal-JobManager"), () -> {
|
||||
if (SignalDatabase.inTransaction()) {
|
||||
Log.w(TAG, "Enqueuing a job while in a transaction!", new Throwable());
|
||||
}
|
||||
return ThreadUtil.isMainThread();
|
||||
}));
|
||||
this.jobTracker = configuration.getJobTracker();
|
||||
this.jobController = new JobController(application,
|
||||
configuration.getJobStorage(),
|
||||
|
||||
Reference in New Issue
Block a user