hiyaryan / the-cdj

The Cognitive Distortion Journal (CDJ) is a smart journaling tool that helps remedy distorted thinking. It can feel impossible to follow the CBT technique of labeling distorted thinking and finding alternative modes of thought (i.e. reframing) while cognitive distortions are occurring. The CDJ does that work for you. -- The CDJ is in beta testing!!
https://thecdj.app
3 stars 0 forks source link

Merge API call for resources in Entries to one. #99

Closed hiyaryan closed 7 months ago

hiyaryan commented 7 months ago

Whenever a user navigates to the Entries page, all of their entries are pulled into view so that they may be displayed in recent thoughts (not all of them should be which is what this issue, #77, covers).

This API call only happens once when the Entries page is initially loaded

0|the-cdj | GET /journals/:journalId/entries/ 200 23.347 ms - 10088

Whenever a user clicks on a recent thought, two API calls are made. One retrieves the thought and analysis, and the other retrieves the chat. This is not very efficient, especially if the user is clicking through their thoughts. It's even less efficient when the Entries page first loads because now a third API call is made.

0|the-cdj | GET /journals/:journalId/entries/:entryId/analysis 200 40.091 ms - 1844 0|the-cdj | GET /journals/:journalId/entries/:entryId/chat 200 20.810 ms - 8510

This can be made more efficient in two places requiring only one API call in both cases, when the Entries page is first loaded, and when an entry with all of its data is loaded. When the entries page is first loaded, the focused thought is the first of the recent entries. This can simply be set to the focused thought (will need more than a little refactoring). And then for each consecutive request to view a specific thought, on the backend, the two endpoints can simply be merged into one.

hiyaryan commented 7 months ago

Updated to major due to changes made in schema. See PR #113, which resolves this issue, for details.