I’m capturing the User’s DOB on signup though am converting this into an age to help with search speed. We can build a scheduled workflow to update the age once a year but I was wondering whether anyone has figured out a way to use a backend trigger to do something like this? i.e.
When User’s DOB’s day&month are equal to current date’s day&month → Age+1
Hey,
Database triggers works only when some data changed, so regular workflows that will “re-count age”(safer option then + 1) is the only way to go for you.
As you yourself mentioned, in my opinion, this seems to be the best solution: You can also, as soon as the birthdate is saved, schedule a new workflow for the day of the birthday. Then, increment the age field by +1, and immediately schedule an action for the following year. This way, you create a loop that updates the field every year.
It is also possible to execute this action when a user logs in, of course. As soon as they are logged in, you will then have up-to-date data. This way, you avoid using unnecessary workloads. However, it also depends somewhat on how your app is structured.
6-year-old Timmy walked into a pub, and asked for a beer. The publican asked for ID, and then agreed. Which day of the year is his birthday?
I always try to leave computed values out of the database and have them calculated when needed. Of course, if age is stored it makes charts easier to do.
If you’re using the DOB as a search constraint then it won’t make any speed difference since it’s all done in Bubble’s backend.
If you are doing the age filtering using :filtered then there will be a huge difference depending on the returned data size and shifting your age filtering to the search constraint will then make a difference.
BUT, what happens if I log in Thursday (which will re-calculate my age) and stay logged in until Sunday. Friday is my birthday. That means I have all day Friday, Saturday and Sunday where the system has my incorrect age because I never logged back out and logged back in to trigger the re-calculation of my age.
I assume you mean “change their age” to mean “change their DOB”.
I think you need to let them change their DOB. Why? Well, I know way too many people who will give a fake DOB just to get into the app to try it, thinking they don’t want to give the app too much personal info yet. Then when they feel comfortable with the app and they know an accurate DOB means something important (like free coffee on your birthday) they’ll update the DOB to the correct value.