-
Notifications
You must be signed in to change notification settings - Fork 3
Fix/applics 1683 improve loading speed examination timetable items #2968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JanPhillips
wants to merge
13
commits into
main
Choose a base branch
from
fix/APPLICS-1683-improve-loading-speed-examination-timetable-items
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
afad79d
feat(api): added columns path and documentCount to folder;path is set…
JanPhillips 18d18dd
feat(api): documentCount is increased/decreased when a file is added/…
JanPhillips d7dbd6c
feat(api): examination timetable item can only be deleted when folder…
JanPhillips 881ec08
fix(api): documentCount of folder is updated when files moved; fixed …
JanPhillips e05c80f
feat(api): script for populating path column for each Folder in db (A…
JanPhillips 8818d5e
fix(api): a test script that asserts the of each entry in Folder tab…
JanPhillips 5493276
fix(api): small refactoring and more error handling (APPLICS-1683)
JanPhillips 21448ad
fix(api): test script checks paths for all Folders, Promise.All() for…
JanPhillips d05263f
fix(web): using strict equality on submission count
JanPhillips 0835393
fix(api): using const instead of let (APPLICS-1683)
JanPhillips 8288f8c
fix(api): refactored recursivelySetPaths() (APPLICS-1683)
JanPhillips a245d22
Merge branch 'main' into fix/APPLICS-1683-improve-loading-speed-exami…
JanPhillips b31ff44
Merge branch 'main' into fix/APPLICS-1683-improve-loading-speed-exami…
JanPhillips File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
apps/api/src/database/migrations/20250922072142_folder_document_count_and_path/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| BEGIN TRY | ||
|
|
||
| BEGIN TRAN; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE [dbo].[Folder] ADD [documentCount] INT, | ||
| [path] NVARCHAR(1000); | ||
|
|
||
| COMMIT TRAN; | ||
|
|
||
| END TRY | ||
| BEGIN CATCH | ||
|
|
||
| IF @@TRANCOUNT > 0 | ||
| BEGIN | ||
| ROLLBACK TRAN; | ||
| END; | ||
| THROW | ||
|
|
||
| END CATCH |
19 changes: 19 additions & 0 deletions
19
...pi/src/database/migrations/20251002103819_document_count_default_value_zero/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| BEGIN TRY | ||
|
|
||
| BEGIN TRAN; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE [dbo].[Folder] ADD CONSTRAINT [Folder_documentCount_df] DEFAULT 0 FOR [documentCount]; | ||
|
|
||
| COMMIT TRAN; | ||
|
|
||
| END TRY | ||
| BEGIN CATCH | ||
|
|
||
| IF @@TRANCOUNT > 0 | ||
| BEGIN | ||
| ROLLBACK TRAN; | ||
| END; | ||
| THROW | ||
|
|
||
| END CATCH |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { databaseConnector } from '#utils/database-connector.js'; | ||
| import BackOfficeAppError from '#utils/app-error.js'; | ||
|
|
||
| // starting from the root folders, create the path for every child folder, stop when leaf node reached | ||
|
|
||
| // get all root folders | ||
|
|
||
| // for each root folder traverse the tree/folder populating the path column, until leaf reached | ||
| /** | ||
| * | ||
| * @param folder | ||
| * @param {string | null} parentsPath | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async function writePaths(folder, parentsPath) { | ||
| // Is it a root folder? | ||
| if (folder.parentFolderId == null) { | ||
| try { | ||
| const updatedRootFolder = await databaseConnector.folder.update({ | ||
| where: { id: folder.id }, | ||
| data: { path: `/${folder.id}` } | ||
| }); | ||
| // create paths for child folders | ||
| const childFolders = await databaseConnector.folder.findMany({ | ||
| where: { parentFolderId: folder.id } | ||
| }); | ||
| if (!childFolders || childFolders.length === 0) return; | ||
|
|
||
| for (const childFolder of childFolders) { | ||
| await writePaths(childFolder, updatedRootFolder.path); | ||
| } | ||
| } catch (e) { | ||
| throw new BackOfficeAppError(`Error setting path for ${folder.id}`); | ||
| } | ||
| } else { | ||
| try { | ||
| // for child/non-root folders... | ||
| const updatedFolder = await databaseConnector.folder.update({ | ||
| where: { id: folder.id }, | ||
| data: { path: `${parentsPath}/${folder.id}` } | ||
| }); | ||
|
|
||
| const childFolders = await databaseConnector.folder.findMany({ | ||
| where: { parentFolderId: folder.id } | ||
| }); | ||
|
|
||
| if (!childFolders || childFolders.length === 0) return; | ||
|
|
||
| for (const childFolder of childFolders) { | ||
| await writePaths(childFolder, updatedFolder.path); | ||
| } | ||
| } catch (e) { | ||
| throw new BackOfficeAppError(`Error setting path for ${folder.id}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| (async () => { | ||
| const rootFolders = await databaseConnector.folder.findMany({ | ||
| where: { parentFolderId: null } | ||
| }); | ||
| await Promise.all(rootFolders.map((rootFolder) => writePaths(rootFolder, null))); | ||
| })(); |
32 changes: 32 additions & 0 deletions
32
apps/api/src/database/test-scripts/create-paths-test-script.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { databaseConnector } from '#utils/database-connector.js'; | ||
| import assert from 'assert'; | ||
|
|
||
| /* | ||
| * This script checks the paths for all folders | ||
| * | ||
| * usage: `cd` into directory, then `node create-paths-test-script.js` | ||
| * This test script was designed to run using the `node` command | ||
| * instead of `npm run test`, so it can run on a server that does not have | ||
| * libraries for unit testing installed, e.g. production | ||
| * | ||
| */ | ||
|
|
||
| const rootFolders = await databaseConnector.folder.findMany({ | ||
| where: { | ||
| parentFolderId: null | ||
| } | ||
| }); | ||
|
|
||
| await Promise.all(rootFolders.map((folder) => checkPaths(folder, folder.path))); | ||
|
|
||
| async function checkPaths(folder, parentPath) { | ||
| const expectedPath = folder.parentFolderId ? `${parentPath}/${folder.id}` : `/${folder.id}`; | ||
| assert.strictEqual(folder.path, expectedPath); | ||
| const childFolders = await databaseConnector.folder.findMany({ | ||
| where: { | ||
| parentFolderId: folder.id | ||
| } | ||
| }); | ||
| if (!childFolders || childFolders.length === 0) return; | ||
| for (const child of childFolders) await checkPaths(child, expectedPath); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could rename
updateDocuments[0]toupdatedDocumentObjectsandupdateDocuments[1]could be renamed todocumentVersionObjectssomething likeconst [updatedDocumentObjects, documentVersionObjects] = updateDocuments;