I have a webpage that keeps track of all the incomes and expenses of a business. The user can see its businesses total balance any day, from the day the business was created. So for example, if today is 9/15/22 and the business was created on 6/12/21, the user can see the business total balance from any day since 6/12/21.
Calculating the total balance is easy: Incomes - expenses = total balance
The problem is that when the business has a lot of time running, expenses and incomes can be thousands, so querying them all from db and operating with all of them at the same time can be very slow.
Can you think of any other way of keeping track of this? I thought about checkpoints every month, but i dont really know if that is the best idea. Im working with nodejs and mysql. Thanks a lot.