Skip to content

Commit

Permalink
Drop the legacy upgrade/initialization code
Browse files Browse the repository at this point in the history
Schema 11 was introduced in 2012, and decks that still are <11 are very
rare. The desktop dropped support for schema 10 back in early 2020.

This also removes the need to modify SCHEMA_VERSION when switching
between TESTING_USE_V16_BACKEND.
  • Loading branch information
dae committed Jun 18, 2022
1 parent 0daa7a5 commit daf4ce9
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 274 deletions.
17 changes: 10 additions & 7 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
Expand All @@ -44,9 +43,7 @@
import com.ichi2.anki.services.BootService;
import com.ichi2.anki.services.NotificationService;
import com.ichi2.compat.CompatHelper;
import com.ichi2.libanki.backend.DroidBackend;
import com.ichi2.libanki.backend.RustDroidBackend;
import com.ichi2.libanki.backend.RustDroidV16Backend;
import com.ichi2.libanki.Consts;
import com.ichi2.utils.AdaptionUtil;
import com.ichi2.utils.ExceptionUtil;
import com.ichi2.utils.LanguageUtil;
Expand Down Expand Up @@ -89,11 +86,9 @@ public class AnkiDroidApp extends Application {

/**
* Toggles opening the collection using schema 16 via the Rust backend
* and using the V16 versions of the major 'col' classes: models, decks, dconf, conf, tags
* and using the V18 versions of the major 'col' classes: models, decks, dconf, conf, tags
*
* UNSTABLE: DO NOT USE THIS ON A COLLECTION YOU CARE ABOUT.
*
* Set this and {@link com.ichi2.libanki.Consts#SCHEMA_VERSION} to 16.
*/
public static boolean TESTING_USE_V16_BACKEND = false;

Expand Down Expand Up @@ -514,4 +509,12 @@ public static BackendFactory currentBackendFactory() {
return new BackendV11Factory();
}
}

public static int activeSchemaVersion() {
if (TESTING_USE_V16_BACKEND) {
return Consts.BACKEND_SCHEMA_VERSION;
} else {
return Consts.LEGACY_SCHEMA_VERSION;
}
}
}
2 changes: 0 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/CollectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
import androidx.annotation.VisibleForTesting;
import timber.log.Timber;

import static com.ichi2.libanki.Consts.SCHEMA_VERSION;

/**
* Singleton which opens, stores, and closes the reference to the Collection.
*/
Expand Down
2 changes: 0 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import com.ichi2.anki.web.CustomSyncServer.handleSyncServerPreferenceChange
import com.ichi2.anki.web.CustomSyncServer.isEnabled
import com.ichi2.compat.CompatHelper
import com.ichi2.libanki.Collection
import com.ichi2.libanki.Consts
import com.ichi2.libanki.Utils
import com.ichi2.libanki.backend.exception.BackendNotSupportedException
import com.ichi2.libanki.utils.TimeManager
Expand Down Expand Up @@ -1314,7 +1313,6 @@ class Preferences : AnkiActivity() {
setDefaultValue(AnkiDroidApp.TESTING_USE_V16_BACKEND)
setOnPreferenceClickListener {
AnkiDroidApp.TESTING_USE_V16_BACKEND = true
Consts.SCHEMA_VERSION = 16
(requireActivity() as Preferences).restartWithNewDeckPicker()
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog
import com.ichi2.anki.*
import com.ichi2.async.Connection
import com.ichi2.libanki.Consts
import com.ichi2.libanki.utils.TimeManager
import com.ichi2.utils.SyncStatus
import com.ichi2.utils.UiUtil.makeBold
Expand Down Expand Up @@ -375,7 +374,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() {
} catch (e: Exception) {
Timber.w(e, "Failed to get database version, using -1")
}
res().getString(R.string.incompatible_database_version_summary, Consts.SCHEMA_VERSION, databaseVersion)
res().getString(R.string.incompatible_database_version_summary, AnkiDroidApp.activeSchemaVersion(), databaseVersion)
}
else -> requireArguments().getString("dialogMessage")
}
Expand Down
5 changes: 3 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ object Consts {
const val STARTING_FACTOR = 2500

// deck schema & syncing vars
@JvmField
var SCHEMA_VERSION = 11
const val LEGACY_SCHEMA_VERSION = 11
/** Only used by the dialog shown to user */
const val BACKEND_SCHEMA_VERSION = 18

/** The database schema version that we can downgrade from */
const val SYNC_MAX_BYTES = (2.5 * 1024 * 1024).toInt()
Expand Down
Loading

0 comments on commit daf4ce9

Please sign in to comment.