thermobased / flask-webapp

0 stars 0 forks source link

Avoid multiple queries when deleting a habit #10

Closed gnull closed 3 months ago

gnull commented 4 months ago

https://github.com/thermobased/flask-webapp/blob/bc938fa015090d7f46bfcf661d026edc26875b90/main.py#L165-L168

Sqlite allows deleting the datapoints automatically on deletion of the habit. There's multiple ways to do that. My first impression is that ON DELETE CASCADE is the most straightforward way to do it.

Also, the first SELECT is unnecessary. You can just DELETE entries directly (if they don't exist, you won't delete anything).

Using the two suggestions above, you can implement habit deletion with a single DELETE FROM habits WHERE habit = ? and login = ? query. This simplifies the code, and also uses Sqlite in a more canonical way.

Ivan

thermobased commented 3 months ago

fixed by d21abd3e7d7e5ed9250c5b0d70591afb75514a48