Skip to content

Commit

Permalink
Re-enable FTS optimization after deletes.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Feb 14, 2023
1 parent dda5037 commit afbce6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1533,12 +1533,11 @@ private static long getReleaseChannelThreadId(boolean hasSeenReleaseChannelStori
return releaseChannelThreadId;
}

public void deleteGroupStoryReplies(long parentStoryId) {
private void deleteGroupStoryReplies(long parentStoryId) {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
String[] args = SqlUtil.buildArgs(parentStoryId);

db.delete(TABLE_NAME, PARENT_STORY_ID + " = ?", args);
OptimizeMessageSearchIndexJob.enqueue();
}

public int deleteStoriesOlderThan(long timestamp, boolean hasSeenReleaseChannelStories) {
Expand Down Expand Up @@ -1940,6 +1939,8 @@ public void markAsRemoteDelete(long messageId) {
db.endTransaction();
}

OptimizeMessageSearchIndexJob.enqueue();

ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(new MessageId(messageId));
ApplicationDependencies.getDatabaseObserver().notifyConversationListListeners();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.thoughtcrime.securesms.jobs

import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.jobmanager.Data
import org.thoughtcrime.securesms.jobmanager.Job
import org.thoughtcrime.securesms.transport.RetryLaterException
import java.lang.Exception
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

/**
* Optimizes the message search index incrementally.
Expand All @@ -16,8 +18,7 @@ class OptimizeMessageSearchIndexJob private constructor(parameters: Parameters)

@JvmStatic
fun enqueue() {
// TODO [greyson] Temporarily disabled until we can figure out what to do.
// ApplicationDependencies.getJobManager().add(OptimizeMessageSearchIndexJob())
ApplicationDependencies.getJobManager().add(OptimizeMessageSearchIndexJob())
}
}

Expand All @@ -33,15 +34,14 @@ class OptimizeMessageSearchIndexJob private constructor(parameters: Parameters)
override fun getFactoryKey() = KEY
override fun onFailure() = Unit
override fun onShouldRetry(e: Exception) = e is RetryLaterException
override fun getNextRunAttemptBackoff(pastAttemptCount: Int, exception: Exception): Long = 1.minutes.inWholeMilliseconds
override fun getNextRunAttemptBackoff(pastAttemptCount: Int, exception: Exception): Long = 30.seconds.inWholeMilliseconds

override fun onRun() {
// TODO [greyson] Temporarily disabled until we can figure out what to do.
// val success = SignalDatabase.messageSearch.optimizeIndex(10.seconds.inWholeMilliseconds)
//
// if (!success) {
// throw RetryLaterException()
// }
val success = SignalDatabase.messageSearch.optimizeIndex(5.seconds.inWholeMilliseconds)

if (!success) {
throw RetryLaterException()
}
}

class Factory : Job.Factory<OptimizeMessageSearchIndexJob> {
Expand Down

0 comments on commit afbce6f

Please sign in to comment.