Skip to content

Cache improvements - #3

Open
saulojg wants to merge 16 commits into
Sebbia:masterfrom
saulojg:master
Open

Cache improvements#3
saulojg wants to merge 16 commits into
Sebbia:masterfrom
saulojg:master

Conversation

@saulojg

@saulojg saulojg commented May 4, 2017

Copy link
Copy Markdown

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:

public void testNonCachedReads(){
    Category cached, otherCached, notCached;

    cached = new Category();
    cached.save();

    // read and retrieve from cache
    cached = new Select().from(Category.class).where("id = ?", cached.getId()).executeSingle();
    otherCached = new Select().from(Category.class).where("id = ?", cached.getId()).executeSingle();

    assertTrue(cached==otherCached);

    notCached = new Select().from(Category.class).where("id = ?", cached.getId())
            .setUseCache(false).executeSingle();

    assertTrue(cached!=notCached);
}

saulojg and others added 10 commits May 4, 2017 17:58
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.
saulojg added 6 commits March 19, 2026 13:13
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant