How to replace count

Main consumption of the apps work units is the count of elements on the main page (I use it for pagination so we have 1 - X elements, plus this is also used on buttons - so when you are on page X-2 there are more buttons, like the pagination works etc.).

My question - is there a way to get a count of elements in a fast and cheap way.
My elements don’t have slugs, they have numbers but in rare cases an element can get deleted, so not sure if I can take the last nr as the referal (worst case scenario I can do it)
.
So is there any other way? To get the count but cheaper and not count on every page refresh?

1 Like

Have a counter on db and when a user created or deleted + or - that number ?

1 Like

:count is fast and cheap… It’s just an aggregate search. (it’s cheaper than retrieving a number stored in the DB)

So if your WU is high, are you sure that’s all you’re doing? (i.e. are you actually loading data to the page instead, unnecessarily)?

Or are you just doing way more agg searches than you need to?

But you can speed things up by using approximate count, or reduce the number of required agg searches (in some cases) by using cached aggregation.

1 Like