Lazy Count the number of results
See original GitHub issueIs there any way of counting the number of filtered objects from a realm js query without using JS’s .length property?
Code Sample
I am doing this:
const maleCount = realm.objects('Person').filtered('gender == "male"').length;
And I wanted to know if there is a faster way of doing so, some Realm method as to not throw away the laziness Realm provides.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to get count of lazy list in most efficient way?
In my VisitRepository I created a new function GetArticleIDsWithVisit(), which makes a direct sql call via db.SqlQuery, returning a Dictionary.
Read more >Count observations by group - dplyr
count () lets you quickly count the unique values of one or more variables: df %>% count(a, b) is roughly equivalent to df...
Read more >Lazy Sort: Counting Comparisons - jaspervdj
So, we get to the main trick I wanted to talk about: how do we benchmark this, and can we add unit tests...
Read more >Lazy Queries - Lucee Documentation
It does not know how many records there are. When you loop you can count the records, so you know the total number...
Read more >Python: Count the occurrences of each word in a given sentence
{'the': 2, 'jumps': 1, 'brown': 1, 'lazy': 1, 'fox': 1, 'over': 1, ... print('The number of words in this sentence is: ' +...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
.length
is implemented using functions in Realm Core (our storage/query engine), and it is a fairly cheap to compute.If you have
the second invocation of
.length
with not rerun the query.The short answer is that we don’t expose any other method to compute the length of a result set.
Since realm pretty much locks the entire app while it is running a query (not async), I would say the time budget is not too high. This is an operation intended to run shortly after an app start to do some cleanup and gather statistics. I guess I will need to test a real use-case and time it. But constant time sounds decent for this, as we are talking of about a few thousand items.