Skip to content

Improve Asynchronous Image Deletion in deleteQuestion #74

Description

@beetle-ai

ISSUE_NUMBER: GH-33

Description

The deleteQuestion function in controllers/quesController.js uses forEach with async/await to delete images associated with question options. This approach doesn't guarantee that all images are deleted before the function proceeds, potentially leading to issues with resource cleanup or rate limits.
File: repositories/QuestionBankapi/controllers/quesController.js
Line: 128-132
Severity: medium

Current Behavior

The forEach loop doesn't wait for each image deletion to complete before moving to the next iteration.

Expected Behavior

All images should be deleted before the function proceeds to delete the question and update the user.

Suggested Fix

Replace forEach with Promise.all to ensure all image deletions are completed before proceeding.

Code Context

question.options.forEach(async (option) => {
if (option.images && option.images.length > 0) {
await deleteImages(option.images);
}
});

Additional Notes

Using Promise.all ensures proper resource cleanup and avoids potential issues with rate limits on the image deletion service.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions