objectbox / objectbox/objectbox-java
Request : LiveData observing Query.count instead of Query.find
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.6k
- Forks
- 311
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I'd like to use LiveData to observe the number of items resulting of a given query (the equivalent of Query.count() or Query.findLazy().size()).
As of v2.4.0, LiveData only calls Query.find, so the only implementation I came up with is not optimal at all
// Get all results as objects
// NB : db.queryContentSearch is a Query<Content>
ObjectBoxLiveData<Content> livedata = new ObjectBoxLiveData<>(db.queryContentSearch(query, metadata, favouritesOnly));
// Instanciated objects are useless because we just actually count them !
MediatorLiveData<Integer> result = new MediatorLiveData<>();
result.addSource(livedata, v -> result.setValue(v.size()));
return result;
=> Would it be possible in future versions to build LiveData's that observe Query.count ?
Or have I overlooked a feature that already exists ?
Thanks a lot for your help,
-Robb
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the current LiveData behavior that calls Query.find, then compare the Query.count and Query.findLazy APIs described in the issue. Done means a LiveData option can observe a query's count without materializing all result objects and updates when the query results change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- database, mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100