Skip to content
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

Fix for device deletion #7

Merged
merged 3 commits into from
Sep 26, 2024
Merged

Fix for device deletion #7

merged 3 commits into from
Sep 26, 2024

Conversation

JahleelAbraham
Copy link
Collaborator

This PR contains a change in structure for the DELETE /devices/{id} route.

Despite it passing tests, it presented some issues on some Bluecherry deployments. With the help of DTV, the approach was changed to a promise chain, this will ensure that the records in the database are properly disposed of before moving to delete the main device record.

Along side this fix, there are minor spelling corrections and code formatting tweaks.

Copy link
Contributor

@andrey-utkin andrey-utkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I request that you...

  • add a test which would reproduce the problem you're targeting here, so that in future we could change the code again and not do as much thorough manual testing. As this is a timing problem, there are two approaches possible:
    • stress-test, repeatedly hammer it with a high count of repetitions which would ensure the old version of code hits the problem;
    • instrument the product code with some "internal_test_delay" hidden parameter (ideally not affecting the user-visible API) to insert a long delay into a deletion process, so that we could insert a Media entry in the test code so that delete operation fails.
  • Leave the old, non-repeated function available (ideally as an organic part of your looped logic): as soon as the schema change allowing cascade delete db: Allow DELETE FROM Devices, cascade Media and EventsCam bluecherry-apps#696 is released, the more complex repeat loop can be dropped, let's make it convenient to drop it.
  • Restructure the code to avoid such deep code nesting. So many braces! There are no obvious mistakes, but I can't really say I could follow the logic of the code. I understand that JS dictates some of that, asynchrony dictates some of that, and part of the problem is my unfamiliarity, but still I request you try as I believe some improvement on readability by reduction of nesting should be possible.

@JahleelAbraham JahleelAbraham merged commit e0cd667 into main Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants