Efficient way to create the next number

Hello All,

I have a button which create a new “job” in my app. This button creates the new job and assigns it the next “work#” in the system based on a search of the (last item), then adding 1 to it. I was wondering if there is a more efficient way. Because after that, I create another item that is linked to it, then as a third step, I link them all back together. An auto-increment field would be great, but this is the best I can figure out.

Sometimes clicking this button literally stalls the app for 10 seconds, and sometimes it takes 3-4 seconds. Either is slow, but 10+ seconds is unbearable. Additionally, if there are any “efficiency guides” please send me the link. I know I have seen some (from the founders), but I don’t feel like they discuss this topic specifically).

image
image
image

Thanks very much,

maybe use custom states

Hi troyr,

I think what boston85719 is referring to is:
Upon page load, or when you open the group with the button inside it,
you can set a state on the group or button that is type number.
This number is “Search for equipments:count + 1”
Then when you use unit# = you use state’s x for instance

That way when you create the thing, the number was already calculated and does not have to be calculated in the workflow of the button.


hope this helps
regards
Julius

Hello,

Yes that was a thought, but this would be used by multiple people at a time. So if i updated a state, then someone else ran the page and created a new entry, the state would be wrong.

If at the end of the day that is the best option then that’s ok, I just wanted to make sure there wasn’t a more efficient way to find the last item created in a thing.

I would love to find a thread that talks about efficient searches like this.

Unless, is there a way to have a state shared between users? Or perhaps have a database entry that only contains the last “thing#”?

Would that be efficient?

Edit:. Also Julius, is a search : count faster than :lastitem? Is this listed anywhere? I’m not trying to contradict, simply curious.

Thanks

Troy, instead of a custom state you could use a “hidden input”. Put an input element of type integer on the page and set it to be invisible on page load. Use the same “Do a search for: last item + 1” logic as the initial content of the input and you should be good. This will automatically update even if someone else creates a new thing after the page has loaded.

2 Likes