Fix/applics 1683 improve loading speed examination timetable items#2968
Fix/applics 1683 improve loading speed examination timetable items#2968JanPhillips wants to merge 13 commits intomainfrom
Conversation
… for new folders (APPLICS-1683)
…deleted (APPLICS-1683)
… is empty (APPLICS-1683)
…tests(APPLICS-1683)
There was a problem hiding this comment.
Pull Request Overview
This PR improves the loading speed of examination timetable items by implementing a document count tracking system using folder document counts instead of potentially expensive real-time queries.
- Adds
documentCountandpathfields to the Folder database model - Implements functions to efficiently track document counts when documents are added/removed/moved
- Updates examination timetable logic to use the cached document count instead of querying submissions
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/web/src/server/views/applications/case-timetable/components/timetable-items-list.component.njk | Updates template logic to handle numeric submission counts and null states |
| apps/web/src/server/applications/case-timetable/tests/snapshots/applications-timetable.test.js.snap | Updates test snapshots to reflect removal of delete links for folders with submissions |
| apps/api/src/server/repositories/folder.repository.js | Adds document count tracking functions and folder path management |
| apps/api/src/server/applications/examination-timetable-items/examination-timetable-items.controller.js | Replaces submission validation with document count lookup |
| apps/api/src/server/applications/application/documents/document.service.js | Integrates document count updates when documents are created/deleted |
| apps/api/src/database/schema.prisma | Adds documentCount and path fields to Folder model |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...erver/applications/examination-timetable-items/__tests__/examination-timetable-items.test.js
Outdated
Show resolved
Hide resolved
…e is correct (APPLICS-1683)
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| return databaseConnector.$executeRaw`UPDATE folder SET documentCount = documentCount - ${decreaseBy} | ||
| WHERE ${folder.path} LIKE CONCAT(path, '%')`; |
There was a problem hiding this comment.
This raw SQL query is vulnerable to SQL injection. The folder.path value should be parameterized or sanitized before being used in the query.
There was a problem hiding this comment.
| return databaseConnector.$executeRaw`UPDATE folder SET documentCount = documentCount + ${increaseBy} | ||
| WHERE ${folder.path} LIKE CONCAT(path, '%')`; |
There was a problem hiding this comment.
This raw SQL query is vulnerable to SQL injection. The folder.path value should be parameterized or sanitized before being used in the query.
There was a problem hiding this comment.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...b/src/server/views/applications/case-timetable/components/timetable-items-list.component.njk
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
a3664b6 to
d05263f
Compare
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated no new comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...rc/server/applications/examination-timetable-items/examination-timetable-items.controller.js
Show resolved
Hide resolved
…nation-timetable-items
|
|
||
| // updateDocuments[0] is the array of Document objects updated | ||
| // updateDocuments[1] is array of DocumentVersion objects | ||
| if (updateDocuments[0].count === 0 || updateDocuments[1].count === 0) { |
There was a problem hiding this comment.
we could rename updateDocuments[0] to updatedDocumentObjects and updateDocuments[1] could be renamed to documentVersionObjects something like const [updatedDocumentObjects, documentVersionObjects] = updateDocuments;
…nation-timetable-items
Optimisation of loading speed for examination timetable items
CBOS Exam timetable page loading speed
The loading speed of the examination timetable items page is slow due to how the number of documents within a folder and its subfolders is counted. Currently, a recursive traversal of the folder structure, which involves calls to the database, this happens for each examination timetable item, when there are many timetable items on the page, this causes the page to load slowly. The document count is required to determine if an examination timetable item can be deleted, items with no files can be deleted.
This PR has sped up the loading time by utilising a concept called Materialised Paths. Two new columns have been added to the Folder table,
documentCountandpath, combined with new logic for setting, updating, and getting these values, only 1 database query is required to get the the document count for any folder. ThedocumentCountfor all ancestor folders are update when files are uploaded, deleted or moved. In terms of Big O notation I believe this changes the effort to get the document count of a folder fromO(n)(where n = number of child folders) toO(1).For existing Folders
Included in this PR is a script file,
apps/api/src/database/seed/create-paths.jsthat can by run on a server to set thepathvalue for eachFolder. There is also a test scriptapps/api/src/database/test-scripts/create-paths-test-script.jsthat can be run afterwards to check the changes were successful.Before running
Run a migration on the DB, to ensure that the
Foldertable gets the new columnsdocumentCountandpathIssue ticket number and link
Type of change 🧩
Checklist before requesting a review