Dietitians create base meal plans in my app. Then they send their clients to my app and my app will adapt the base meal plans to the caloric requirements of each client (the food will be the same as in the base plan but the quantities are adapted to each client’s caloric requirement).
So for each client, all the food in the base meal plan is copied (usually they are +200 items (food and ingredients) copied and each item has more than 20 records to be modified, so yes, for each client I modify around +4000 records, that is why it takes so long).
Why do I copy all the items from the base plan and not just use the same items from the base plan and adapt the quantities in the front end without modifying the db for each client?
Because if dietitians modify their base plan, for example, if they change an apple for a carrot, then all the client plans that were generated using that base plan and that had an apple, would be modified and now have a carrot.
So, client meal plans that were already generated should remain the same for ever, no matter if the dietitian modify the base meal plan.
I am thinking that a solution might be to allow the dietitians to release new versions of their base meal plans.
So, if they would like to modify an item of the existing base meal plan they would have to generate a new version of it, so all the items would be copied (this would still take 3 minutes) but just once.
Then, for every client meal plan I would just make reference to the latest version of the base meal plan items, the adapted quantities I can set them up with a math formula in the front end, without touching the db.
What do you think about this possible solution? I will still have the 3 min process but only the dietitians will experience it when releasing new versions, not every client when generating their adapted meal plans. Do you think there is any other way that I can do this without the 3 minutes wait?