Request : LiveData observing Query.count instead of Query.find
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
The ObjectBoxLiveData implementation is basically just a thin wrapper around an ObjectBox query subscription (https://docs.objectbox.io/data-observers-and-rx).
That currently does not support observing the count of the results only.
As a workaround one could use BoxStore.subscribe(Content.class) and then get the count each time onData is called. Then wrap this in a LiveData?