[Solved] Less searching

Hi, I am trying to add a thing to a database, and every new thing I add, I would like to increase its number by 1.

At the moment, whenever I add a new entry, I search for all current entries:count + 1

However, that seems like it might get inefficient once there are lots of these entries (and probably expensive in WU?). Is there a better way of doing it?


Well, you could add/create a new field somewhere, which is a list of each thing. When a thing is created, you add it to the list. And the opposite if a thing is deleted. That way, you can reference that list and get the :count + 1.

That was what they recommended in that WU webinar—the complete opposite way of doing things than we were led to believe was optimized before.

Edit: there is a limit on the number of things that can be stored in a list. Honestly, I’d just keep riding with the way you’re currently doing it and you can pivot later if need be.

1 Like

Perfect, thanks!

Hi Mac, If I understand what you are saying, when it comes to showing a user their statistics, the way to minimise WUs might be to create a statistics data type, where I make calculations on the data there every time I change a thing?

As such, I create a data type statistics, and each user’s statistics live within that data type.

For instance, number of tasks, or average duration of those tasks.

Every time someone adds a task, I get it to update those two figures, and then for the page where I show the statistics, I just search for that user within my Statistics type, which will be a single entity / row within the database.

Am I understanding correctly? Thanks so much!

Doing a search: count only returns a single number - so it doesn’t matter if there are 3 things or 300,000 in the database, the WU cost remains the same.

1 Like

Hi Adam,

It seems like I have 2 options for setting up my stats.

No stats data type, only tasks data type for all tasks.
Adding a task simply adds a new line to the tasks database.
When the user wants to view their stats, the app searches for the task data for all tasks, and calculates the stats from that large chunk of data.

Tasks data type, for all tasks.
Stats data type for stats per user.
Adding a task adds a line to the tasks database, and also changes the data in the stats type for that user.
When a user wants to view their stats, the app searches the stats data type, a single line in the database, and returns all the entries without needing to calculate anything (as all calculations happened each time a new task was added).

The second one will clearly be faster, but will require a search for the stats entry for the user every time they enter a new task.
The first one will only need a search when the user wants to view their stats.

It seems that you are saying that the first one will cost significantly fewer WUs? Or am I completely getting the wrong end of the stick? I am finding the whole WU thing very confusing and off-putting…!

Thanks, A

I’m not entirely sure what you’re asking about… but if you’re asking about doing a count of things in the database (which you were in your original question), Option 1 will hardly use any WU at all (0.2 to be precise), and will be very fast (even with large lists - i just tested it on a list of 100K things and it was as close to instant as I could detect).

Option 2 will be slower and more costly in WU, no matter how you do it, as you’ll be retrieving more data from the database via a search - which costs a minimum of 0.315 WU plus the data you retrieve)…

Although you shouldn’t need to do any searches here at all - just add the Stats datatype as a field on the User datatype so you can retrieve it via an individual data request rather than a search - which will be faster and cost a LOT less in WU.

Whether any of that matters or no depends on your app and its use - if you’ll only be doing that once in a while it’s probably not important how you do it. But you’ll be doing it hundreds or thousand of times daily, the differences can add up quickly.

1 Like

Sorry for my novice questions, but what’s an individual data request and how does it differ from a do a search for?

My stats page will also be counting numbers in the database (such as total time worked), and calculating things (such as total time worked vs total time scheduled to work).

My thoughts for the stats data type was to calculate these figures for every task add / change done. You seem to be saying that I could retrieve that information without a search? Or do you mean something else?


This topic was automatically closed after 70 days. New replies are no longer allowed.