Currently, some previews and post-hoc analyses are re-calculated several times. This is because they are re-used for other previews or post-hoc analyses. For each of the reports, the code is re-executed which turns out expensive, e.g. it is iterated over all containers (there could be millions) several times to calculate the very same value. This should be avoided in a smart way. Be aware though that the API is meant to always report the true state. We can e.g. first generate the output data, run an analysis, re-run the generation process and run the analysis again. Thus, caching must be reset in once the underlying data is changed.
Ideas:
Use a singleton pattern so that every preview and analysis only exist once in the system.
Use https://docs.python.org/3/library/functools.html - but remember that the cache needs to be cleared once changes happen to the data in the database. It would be best to automate this. Leaving it to users might create unwanted bugs and bugs are worse than longer run times.
Find another smart option that requires little code, is highly maintainable and solves the issue.
Alternative: Leave everything as it is because it is not too much time wasted. A bug that leads to reporting wrong numbers would be much worse than waiting for some seconds more to get the results.
Currently, some previews and post-hoc analyses are re-calculated several times. This is because they are re-used for other previews or post-hoc analyses. For each of the reports, the code is re-executed which turns out expensive, e.g. it is iterated over all containers (there could be millions) several times to calculate the very same value. This should be avoided in a smart way. Be aware though that the API is meant to always report the true state. We can e.g. first generate the output data, run an analysis, re-run the generation process and run the analysis again. Thus, caching must be reset in once the underlying data is changed.
Ideas:
Alternative: Leave everything as it is because it is not too much time wasted. A bug that leads to reporting wrong numbers would be much worse than waiting for some seconds more to get the results.