Closed hiyaryan closed 8 months ago
Updates to the Entries model associates each entry with its EntryAnalysis and EntryConversation. This allows for the use of populate which reduces the number of queries made on the database. This improves the scalability of the application by requiring on one API call to the entries endpoint, and only one query to the database. Changes to the frontend and backend have been implemented in order to achieve this.
These are breaking changes. Since the schema has been updated, all points in the application using the Entries schema, in particular, where new entries are created (POSTS) needed to be updated to reference new conversations, and new analyses. Additionally, anywhere retrievals are made for an entry, the populate method is used if the analysis and chat messages required to reduce the number of API calls. The data structure returned on these API calls has been slightly changed therefore requiring updates to how state variables on the frontend store it.
This PR updates the resources returned for the API endpoint to view a single entry returning all associated documents. These changes improve the scalability of the app by making only one API call to the updated endpoint in the Analysis component. These changes brought updates to how the retrieved data structure is inserted into the components state variables. This also required updating how the Thoughts component inserts the data retrieved from the same endpoint.
The endpoint has been updated from making one db query on two separate API calls to making three on one. This could be reduced to two queries by populating the entry associated with the Analysis. However, a better design would be to insert the IDs of the associated documents on the entry reducing the query made to one.