You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The removeOrganization.ts file has many flaws which can cause slower performance like,
The organization.posts.forEach loop uses async/await syntax to delete each post and comments associated with it one by one, which can result in slower performance. A better approach would be to use Promise.all to run all the delete operations concurrently.
In the current implementation, when removing an organization, we are fetching each user that has joined the organization and removing the organization ID from their joinedOrganizations field one by one. This is not efficient for large organizations with many members. A better approach would be to use the $pull operator to remove the organization ID from all affected users' joinedOrganizations field in one go.
The code has several nested if statements to handle errors and check user roles. This can make the code harder to read and follow. We can use early returns to exit the function early.
The code currently calls the lean() method on several MongoDB queries. While this can improve performance, it can also cause issues with accessing related models or fields. Unless you're sure you don't need the functionality provided by the full model object, it's better to avoid calling lean().
To Reproduce
Steps to reproduce the behavior:
run the local server 'using npm run dev'
run the query removeOrganization
Expected behavior
The following changes can result in enhanced performance,
Remove unnecessary lean() calls
Use $pull operator to remove organization IDs from users' fields.
Use Promise.all to delete posts and comments associated with the organization.
Actual behavior
The current implementation can can result in slow performance
Screenshots
Additional details
Not required
Potential internship candidates
Please read this if you are planning to apply for a Palisadoes Foundation internship PalisadoesFoundation/talawa#359
The text was updated successfully, but these errors were encountered:
nishant3721
changed the title
Use Promise.all to delete posts and comments associated with the organization
Minor changes in removeOrganization.ts to enhance the performance and efficiency
Apr 6, 2023
Describe the bug
The removeOrganization.ts file has many flaws which can cause slower performance like,
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The following changes can result in enhanced performance,
Actual behavior
The current implementation can can result in slow performance
Screenshots
Additional details
Not required
Potential internship candidates
Please read this if you are planning to apply for a Palisadoes Foundation internship PalisadoesFoundation/talawa#359
The text was updated successfully, but these errors were encountered: