0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00
AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
Go to file
Damien Elmes 036b882677 Introduce CollectionManager for preventing concurrent access
Currently there are many instances in the AnkiDroid codebase where
the collection is accessed a) on the UI thread, blocking the UI, and
b) in unsafe ways (eg by checking to see if the collection is open,
and then assuming it will remain open for the rest of a method call.
"Fix full download crashing in new schema case" (159a108dcb) demonstrates
a few of these cases.

This PR is an attempt at addressing those issues. It introduces
a `withCol` function that is intended to be used instead of
CollectionHelper.getCol(). For example, code that previously looked
like:

        val col = CollectionHelper.getInstance().getCol(this)
        val count = col.decks.count()

Can now be used like this:

        val count = withCol { decks.count() }

The block is run on a background thread, and other withCol calls made
in parallel will be queued up and executed sequentially. Because of
the exclusive access, routines can safely close and reopen the
collection inside the block without fear of affecting other callers.

It's not practical to update all the legacy code to use withCol
immediately - too much work is required, and coroutines are not
accessible from Java code. The intention here is that this new path is
gradually bought into. Legacy code can continue calling CollectionHelper.
getCol(), which internally delegates to CollectionManager.

Two caveats to be aware of:
- Legacy callers will wait for other pending operations to complete
before they receive the collection handle, but because they retain it,
subsequent access is not guaranteed to be exclusive.
- Because getCol() and colIsOpen() are often used on the main thread,
they will block the UI if a background operation is already running.
Logging has been added to help diagnose this, eg messages like:

E/CollectionManager: blocked main thread for 2626ms:
    com.ichi2.anki.DeckPicker.onCreateOptionsMenu(DeckPicker.kt:624)

Other changes:

- simplified CoroutineHelpers
- added TR function for accessing translations without a col reference
- onCreateOptionsMenu() needed refactoring to avoid blocking the UI.
- The blocking colIsOpen() call in onPrepareOptionsMenu() had to be
removed. I can not reproduce the issue it reports, and the code checks
for col in onCreateOptionsMenu().
- The subscribers in ChangeManager need to be cleared out at the start
of each test, or two tests are flaky when run with the new schema.
2022-08-16 09:48:12 -05:00
.github chore: Set permissions for GitHub actions 2022-06-28 13:01:28 +05:30
.idea Fix crash during deck filtering (#11880) 2022-07-21 12:36:37 +01:00
AnkiDroid Introduce CollectionManager for preventing concurrent access 2022-08-16 09:48:12 -05:00
annotations Allow JetBrains @Contract annotations 2020-05-14 20:48:36 -05:00
api Remove splitFieldsShouldReturnNullWhenStringIsNull 2022-07-24 14:40:34 -05:00
docs Updated strings from Crowdin 2022-07-04 12:48:46 -05:00
gradle/wrapper Update Gradle Wrapper from 7.5 to 7.5.1. 2022-08-05 19:15:45 -05:00
lint-rules Converted FixedPreferencesTitleLengthTest[LINT TEST] to Kotlin 2022-07-07 20:12:20 +01:00
tools updated mathjax and jquery 2022-06-03 09:00:58 -05:00
.codecov.yml coverage: disable noisy annotations on PRs 2021-03-27 09:45:48 -05:00
.gitattributes chore: Mark user dictionaries as non-generated 2022-04-13 10:42:47 -05:00
.gitignore lint: Add user dictionaries to reduce typos 2022-04-05 17:11:56 -05:00
.prettierignore fix(prettier): Ignore 'build' folder 2022-03-16 11:48:12 +05:30
.prettierrc Change .prettierrc endOfLine to auto 2022-03-17 11:01:04 -05:00
build.gradle Dependency updates 20220730 (#11943) 2022-07-30 13:31:24 -05:00
CONTRIBUTING.md Created CONTRIBUTING.md (#8222) 2021-03-15 07:53:28 -05:00
COPYING Add readme and license file back after accidentally deleting 2014-11-10 02:23:41 +09:00
gradle.properties Use IN_PROCESS compiler strategy only on CI builds 2022-06-11 13:12:10 -05:00
gradlew Update Gradle Wrapper from 7.4.2 to 7.5. 2022-07-14 21:06:24 -05:00
gradlew.bat Update Gradle Wrapper from 7.4.2 to 7.5. 2022-07-14 21:06:24 -05:00
lint-release.xml lint: enable "CheckResult" 2022-07-06 10:57:01 +01:00
lint.gradle lint: enable linting unit tests 2021-10-20 22:58:42 -05:00
pre-commit Make possible to commit hunks again on Kotlin 2022-08-13 15:45:00 +01:00
README.md Add a comment stating not to rename/remove credits 2022-08-04 13:13:40 +03:00
settings.gradle Add lint checks for new time api 2020-08-25 10:04:26 +02:00

release build Open Collective backers and sponsors commit-activity forks stars contributors license

AnkiDroid

A semi-official port of the open source Anki spaced repetition flashcard system to Android. Memorize anything with AnkiDroid!

Features

  • night mode
  • whiteboard
  • progress widget
  • detailed statistics
  • syncing with AnkiWeb
  • write answers (optional)
  • text-to-speech integration
  • more than 6000 premade decks
  • spaced repetition (supermemo 2 algorithm)
  • supported contents: text, images, sounds, MathJax
  • add cards by intent from other applications like dictionaries

Install

Wiki

View Wiki

Help

Check the user manual and the wiki for usage instructions. See the help page for how to submit a bug report or contact a project member, etc.

Contribute

You can contribute to AnkiDroid by beta testing, translating, or submitting code. See the contribution wiki page for more info.

Join Us On

Credits

Code Contributors

Thanks to these awesome code contributors who keep this project going

Sponsors

Backers

Thank you to all our backers! 🙏

Translators

Thanks to our 1400 translators, for allowing us to be available, partially or totally, in 99 languages as of July 2022.

License