in client/src/context/Graph/graphState.js line 8 and onwards, the fetchallgraphs method is defined. I believe this is an operation that gets all the user graphs from the database by matching userID and stores them in the loadedgraphs useState var. However, when the user adds a new graph, this expensive operation of loading all the graphs will have to be redone. Instead, what we can do is simply append the new graph to the loadedgraphs usestate and independently push the new graph into the database without reloading it to the front end with an API call. Let me demonstrate:
Right now:
-> Load all graphs (expensive!)
-> other tasks . . . .
-> User saves a new graph, push graph to database
-> To keep history component updated, load all graphs (expensive!)
What would be better:
-> Load all graphs (expensive!)
-> other tasks . . . .
-> User saves new graph, push graph to database, (new) append new graph to loaded graphs array
-> History component is refreshed based on loaded graphs array (not expensive!)
Of course, this is only an issue when we have many users and when the users actually populate the database to a notable degree. That's why I'm gonna mark this issue as a long term issue :)
in client/src/context/Graph/graphState.js line 8 and onwards, the fetchallgraphs method is defined. I believe this is an operation that gets all the user graphs from the database by matching userID and stores them in the loadedgraphs useState var. However, when the user adds a new graph, this expensive operation of loading all the graphs will have to be redone. Instead, what we can do is simply append the new graph to the loadedgraphs usestate and independently push the new graph into the database without reloading it to the front end with an API call. Let me demonstrate:
Right now:
-> Load all graphs (expensive!)
-> other tasks . . . .
-> User saves a new graph, push graph to database
-> To keep history component updated, load all graphs (expensive!)
What would be better:
-> Load all graphs (expensive!)
-> other tasks . . . .
-> User saves new graph, push graph to database, (new) append new graph to loaded graphs array
-> History component is refreshed based on loaded graphs array (not expensive!)
Of course, this is only an issue when we have many users and when the users actually populate the database to a notable degree. That's why I'm gonna mark this issue as a long term issue :)