Cache improvements - #3
Open
saulojg wants to merge 16 commits into
Open
Conversation
The read cache can be avoided when querying the database, by using the new method com.activeandroid.query.From#setUseCache. Additionally we've fixed the read cache implementation, which was used only by the reflective (legacy) model filler. Now the read cache is applied regardless of the particular model filler in use. We keep the read cache enabled by default mainly for backwards compatibility reasons.
DB concurrency is tricky in Android. The following changes allow a better handling of multithreaded db access: - Write ahead logging is enabled - Connection is configured in onConfigure (SQLiteOpenHelper) - Transactions are made in non-exclusive mode References: - http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#enableWriteAheadLogging() - http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onConfigure(android.database.sqlite.SQLiteDatabase) - http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/database/sqlite/SQLiteDatabase.java#SQLiteDatabase.beginTransaction%28android.database.sqlite.SQLiteTransactionListener%2Cboolean%29 - https://www.sqlite.org/lockingv3.html#reserved_lock - https://www.sqlite.org/lang_transaction.html - http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#beginTransactionNonExclusive()
- Upgrade Gradle wrapper from 1.8 to 8.7 - Update Java source/target compatibility from 1.6 to 1.8 - Replace deprecated 'compile' with 'implementation' - Remove maven-publish plugin and gradle-mvn-push script - Update android-maven-plugin groupId and version in pom-child.xml
Remove eager openDatabase() call from Cache.initialize() to prevent potential ANR on app startup. The database now opens lazily on the first actual query via Cache.openDatabase().
Remove eager openDatabase() call from Cache.initialize() to prevent potential ANR on app startup. The database now opens lazily on the first actual query via Cache.openDatabase().
Copies all @column field values (including the record ID) from a source model onto this instance using reflection over TableInfo's field collection. Both instances must be of the same concrete type. This supports cache-coherence patterns where a deserialized copy needs to update an existing cached instance in-place without changing its object identity.
scanForModel() builds one list from two different kinds of string: under
Robolectric, directories of .class files, and on a device, the dex entries,
which are class names. scanForModelClasses() tells them apart with
isDirectory(), and that is wrong whenever a class name also names a directory.
An app process runs with "/" as its working directory, so a short obfuscated
class name resolves against the filesystem root. R8 full mode flattens classes
into the default package by default, which produces names one character long,
and a class called "d" becomes /d -- on Android a symlink to /sys/kernel/debug.
That is a real directory, so isDirectory() is true, but the app is not allowed
to list it, so listFiles() returns null and the for-each threw:
java.lang.NullPointerException: Attempt to get length of null array
at com.activeandroid.ModelInfo.scanForModelClasses
out of ContentProvider.onCreate, before Application.onCreate, so the app died
on every cold start with "Unable to get provider
com.activeandroid.content.ContentProvider".
A null from listFiles() means this was never a directory we can walk, so it
falls through to the class-name branch instead of returning -- on a device that
is what the string always was, and returning would quietly drop a class from
the scan. Any name that resolves to a *readable* directory is still walked as
one and still missed as a class; distinguishing the two sources properly, rather
than guessing from the filesystem, is the real fix and a larger change.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Commit messages should be clear enough. Please reach me if you need further clarifications.
Both changes were properly tested, but outside the test suite since I can't get it to work right now. Here's the test case: