Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to work with desktop 2.1.54 code #11644

Merged
merged 20 commits into from
Jun 29, 2022
Merged

Commits on Jun 29, 2022

  1. Update to Anki 2.1.54 backend

    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)
    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    ed221af View commit details
    Browse the repository at this point in the history
  2. Set the backend language on app startup

    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    fcf73ab View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    e76b814 View commit details
    Browse the repository at this point in the history
  4. Implement syncing with the backend

    Login, regular syncs and full upload/download work with the new schema
    active, but currently only show progress on the console, and more work
    will be required to polish this up.
    
    I have no previous experience with Kotlin co-routines, so this may not
    be following best practice.
    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    113db83 View commit details
    Browse the repository at this point in the history
  5. Don't store collection reference in DeckTreeNode

    Pass it in to processChildren() instead, which is cleaner, and will
    work better with the move to a backend method.
    
    Speed up deck list by rendering it with the backend
    
    This delegates to the backend to render the deck tree, instead of
    calculating it in Java. On @Arthur-Milchior's large collection with the
    daily limits turned up, the speed difference in an x86_64 sim is
    dramatic: 2.4s with the old Java code, and 70ms with the new Rust code.
    
    - Make deckDueList() private; switch callers to use deckDueTree()
    The backend only provides a deckDueTree(), and switching the calls to
    deckDueList() now will make migration easier in the future.
    
    Squashed from ankidroid#11599
    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    fc18e24 View commit details
    Browse the repository at this point in the history
  6. Add some new flags to local.properties

    legacy_schema=false:  use the new backend code by default
    local_backend=true:   use a locally built copy of the backend
    fatal_warnings=false: don't fail the build on Kotlin warning
    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    4615edc View commit details
    Browse the repository at this point in the history
  7. Expose card info/graph methods

    To enable krmanik#23
    
    Also requires ankidroid/Anki-Android-Backend@4c3eea4
    or similar
    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    aa387d2 View commit details
    Browse the repository at this point in the history
  8. Use named args in backend calls

    This will ensure any reordering or removal of args in the proto files
    in the future will not lead to incorrect arguments being passed in.
    
    + Fix copyright year
    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    2d944c7 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    5fd5d23 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    40aee91 View commit details
    Browse the repository at this point in the history
  11. Add support for colpkg import/export & backups

    + Backup before full download
    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    dc98ce2 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    6bc984f View commit details
    Browse the repository at this point in the history
  13. Remove some unnecessary DB queries when legacy schema disabled

    - collapsed + filtered status is included in the deck list from the
    backend, so does not need to be looked up for each row
    - cache the current deck id at deck list build time, so it doesn't need
    to be looked up for every row (applies to old schema too)
    - skip default deck logic, which is handled by backend
    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    3f3a1c9 View commit details
    Browse the repository at this point in the history
  14. Add mention of TRACESQL env var for debugging

    This became usable in AnkiDroid after we starting capturing stdout.
    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    f857ee1 View commit details
    Browse the repository at this point in the history
  15. Add code to import/export apkg files via the backend

    Also add ChangeManager
    
    Also demonstrates use of backend translations
    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    b114e97 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    8c2fc8c View commit details
    Browse the repository at this point in the history
  17. Restrict backend logging to sync actions

    Previously debug lines from third-party modules were also being included,
    and the HTTP library was leaking the sync key into the logs.
    
    Requires the latest commit to the -Backend repo PR.
    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    c14b217 View commit details
    Browse the repository at this point in the history
  18. Fix V16 toggle in preferences not working

    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    f4f0d16 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    d6a1a36 View commit details
    Browse the repository at this point in the history
  20. Apply suggestions from code review

    dae authored and mikehardy committed Jun 29, 2022
    Configuration menu
    Copy the full SHA
    bb0dc2e View commit details
    Browse the repository at this point in the history