forked from ankidroid/Anki-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashes a few commits: Move the legacy schema toggle into BackendFactory Simplify backend handling; rework collection instantiation When the Rust code was initially introduced, it was not clear whether it would be usable on all devices, or whether it would need to be removed for some reason. This no doubt influenced the design of the existing API, which tries to make it easy to swap the Rust code out with something else. Unfortunately this approach has some downsides: - It makes it somewhat harder to follow, as method calls jump through multiple interfaces before they're actually sent to the backend. - It makes utilizing new methods considerably more cumbersome. For example, take the extract_av_tags() call. It follows the following path: collection method or method in related helper class: https://github.com/ankidroid/Anki-Android/blob/cea79e1b077bc30e7eed8f37529002aae416d34d/AnkiDroid/src/main/java/com/ichi2/libanki/TemplateManager.kt#L242 to generic interface: https://github.com/ankidroid/Anki-Android/blob/cea79e1b077bc30e7eed8f37529002aae416d34d/AnkiDroid/src/main/java/com/ichi2/libanki/backend/DroidBackend.kt#L83 to specific implementation: https://github.com/ankidroid/Anki-Android/blob/cea79e1b077bc30e7eed8f37529002aae416d34d/AnkiDroid/src/main/java/com/ichi2/libanki/backend/RustDroidV16Backend.kt#L57 and if it's unusable with the legacy schema (which I don't believe is actually true in this case), it also needs to be added to the other implementation: https://github.com/ankidroid/Anki-Android/blob/cea79e1b077bc30e7eed8f37529002aae416d34d/AnkiDroid/src/main/java/com/ichi2/libanki/backend/RustDroidBackend.kt#L87 and then finally, a method in the backend module is invoked. The backend module has code generation so that invoking a backend method is as simple as making a method call, but currently you have to weave the call through 3 or so levels of indirection before you can actually use it. With something like 170 available methods, that's a fair amount of extra work required. Rather than trying to insulate libanki from the backend code, this PR drops some of the indirection in favour of the approach the desktop takes: libanki is the insulation layer; it can call freely into the backend methods, but consumers (eg the GUI code) are expected to only call methods on the collection, and not access the backend directly. In addition to the above, collection initialization has been reworked to be more similar to the computer version. Instead of the collection being created from a database object, a backend is passed into the collection creation, and the collection takes care of creating a DB instance that wraps the backend. Remove always-on isUsingRustBackend Drop the legacy upgrade/initialization code 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. Remove DOWNGRADE_REQUIRED and slightly simplify startup error handling - The backend automatically downgrades when required, and possible. No backup is required, as the downgrade happens in a single transaction, and the downgrade code has proven itself over time. - Store the type of failure in getColSafe(), so it can be checked later. Update to work with desktop 2.1.53 code Depends on ankidroid/Anki-Android-Backend#202 Due to the removal and change of a few backend methods, syncing, importing and the card templates screen will not work when the schema16 setting is active (actually schema18 now). To get them working again, those code paths will need to switch to the backend implementations. A few notes: - Downgrading happens automatically when loading the collection in schema11 mode, so the extra code dealing with downgrades & "can downgrade" reporting can be stripped. - Added the ability to run col.set_config("key", JSONObject.NULL), as unit tests were attempting to write the entire collection config, which is no longer supported. - All tests pass on both old and new backends, though the latter required disabling a few failed tests when running with the new schema (eg notetype updating). Integrates, and thus closes ankidroid#11579 and closes ankidroid#11581 Remove the time argument to Storage.collection() Collection does not currently take a time argument, and relies on the global object instead, so this change brings Storage in line with it. Reuse the backend when closing+reopening a collection Avoids having to re-initialize the translations, and reduces leaks (the import + export code leaks backends still)
- Loading branch information
1 parent
821afeb
commit 464e484
Showing
71 changed files
with
681 additions
and
1,408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.