Fix empty emoji search index.
This commit is contained in:
parent
2c74ac8bfa
commit
648506fe04
5 changed files with 79 additions and 1 deletions
|
@ -103,6 +103,10 @@ public final class EmojiSearchIndexDownloadJob extends BaseJob {
|
|||
|
||||
List<EmojiSearchData> searchIndex = downloadSearchIndex(manifest.getVersion(), remoteLanguage);
|
||||
|
||||
if (searchIndex.isEmpty()) {
|
||||
throw new IOException("Emoji search data is empty");
|
||||
}
|
||||
|
||||
SignalDatabase.emojiSearch().setSearchIndex(searchIndex);
|
||||
SignalStore.emojiValues().onSearchIndexUpdated(manifest.getVersion(), remoteLanguage);
|
||||
SignalStore.emojiValues().setLastSearchIndexCheck(System.currentTimeMillis());
|
||||
|
|
|
@ -51,6 +51,7 @@ import org.thoughtcrime.securesms.migrations.DecryptionsDrainedMigrationJob;
|
|||
import org.thoughtcrime.securesms.migrations.DeleteDeprecatedLogsMigrationJob;
|
||||
import org.thoughtcrime.securesms.migrations.DirectoryRefreshMigrationJob;
|
||||
import org.thoughtcrime.securesms.migrations.EmojiDownloadMigrationJob;
|
||||
import org.thoughtcrime.securesms.migrations.EmojiSearchIndexCheckMigrationJob;
|
||||
import org.thoughtcrime.securesms.migrations.LegacyMigrationJob;
|
||||
import org.thoughtcrime.securesms.migrations.MigrationCompleteJob;
|
||||
import org.thoughtcrime.securesms.migrations.OptimizeMessageSearchIndexMigrationJob;
|
||||
|
@ -234,6 +235,7 @@ public final class JobManagerFactories {
|
|||
put(DeleteDeprecatedLogsMigrationJob.KEY, new DeleteDeprecatedLogsMigrationJob.Factory());
|
||||
put(DirectoryRefreshMigrationJob.KEY, new DirectoryRefreshMigrationJob.Factory());
|
||||
put(EmojiDownloadMigrationJob.KEY, new EmojiDownloadMigrationJob.Factory());
|
||||
put(EmojiSearchIndexCheckMigrationJob.KEY, new EmojiSearchIndexCheckMigrationJob.Factory());
|
||||
put(LegacyMigrationJob.KEY, new LegacyMigrationJob.Factory());
|
||||
put(MigrationCompleteJob.KEY, new MigrationCompleteJob.Factory());
|
||||
put(OptimizeMessageSearchIndexMigrationJob.KEY,new OptimizeMessageSearchIndexMigrationJob.Factory());
|
||||
|
|
|
@ -123,6 +123,14 @@ public class EmojiValues extends SignalStoreValues {
|
|||
return getInteger(SEARCH_VERSION, 0);
|
||||
}
|
||||
|
||||
public void clearSearchIndexMetadata() {
|
||||
getStore().beginWrite()
|
||||
.remove(SEARCH_VERSION)
|
||||
.remove(SEARCH_LANGUAGE)
|
||||
.remove(LAST_SEARCH_CHECK)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public @Nullable String getSearchLanguage() {
|
||||
return getString(SEARCH_LANGUAGE, null);
|
||||
}
|
||||
|
|
|
@ -134,9 +134,10 @@ public class ApplicationMigrations {
|
|||
static final int EMOJI_VERSION_8 = 90;
|
||||
static final int SVR2_MIRROR = 91;
|
||||
static final int ATTACHMENT_CLEANUP_3 = 92;
|
||||
static final int EMOJI_SEARCH_INDEX_CHECK = 93;
|
||||
}
|
||||
|
||||
public static final int CURRENT_VERSION = 92;
|
||||
public static final int CURRENT_VERSION = 93;
|
||||
|
||||
/**
|
||||
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
|
||||
|
@ -606,6 +607,10 @@ public class ApplicationMigrations {
|
|||
jobs.put(Version.ATTACHMENT_CLEANUP_3, new AttachmentCleanupMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.EMOJI_SEARCH_INDEX_CHECK) {
|
||||
jobs.put(Version.EMOJI_SEARCH_INDEX_CHECK, new EmojiSearchIndexCheckMigrationJob());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package org.thoughtcrime.securesms.migrations;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.signal.core.util.SqlUtil;
|
||||
import org.thoughtcrime.securesms.database.EmojiSearchTable;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobs.DownloadLatestEmojiDataJob;
|
||||
import org.thoughtcrime.securesms.jobs.EmojiSearchIndexDownloadJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
|
||||
/**
|
||||
* Schedules job to get the latest emoji search index if it's empty.
|
||||
*/
|
||||
public final class EmojiSearchIndexCheckMigrationJob extends MigrationJob {
|
||||
|
||||
public static final String KEY = "EmojiSearchIndexCheckMigrationJob";
|
||||
|
||||
EmojiSearchIndexCheckMigrationJob() {
|
||||
this(new Parameters.Builder().build());
|
||||
}
|
||||
|
||||
private EmojiSearchIndexCheckMigrationJob(@NonNull Parameters parameters) {
|
||||
super(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUiBlocking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getFactoryKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performMigration() {
|
||||
if (SqlUtil.isEmpty(SignalDatabase.getRawDatabase(), EmojiSearchTable.TABLE_NAME)) {
|
||||
SignalStore.emojiValues().clearSearchIndexMetadata();
|
||||
EmojiSearchIndexDownloadJob.scheduleImmediately();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean shouldRetry(@NonNull Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class Factory implements Job.Factory<EmojiSearchIndexCheckMigrationJob> {
|
||||
@Override
|
||||
public @NonNull EmojiSearchIndexCheckMigrationJob create(@NonNull Parameters parameters, @Nullable byte[] serializedData) {
|
||||
return new EmojiSearchIndexCheckMigrationJob(parameters);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue