joaovitoriasilva / endurain

Endurain is a self-hosted fitness tracking service designed to give users full control over their data and hosting environment
https://docs.endurain.com/
GNU General Public License v3.0
656 stars 15 forks source link

optimize users's crud.py database queries #32

Closed movassaghi6 closed 2 weeks ago

movassaghi6 commented 2 months ago

This update includes multiple improvements to the crud.py file for the User table:

  1. Optimized get_users_number function by querying the indexed username field, improving performance when counting users.
  2. Refactored get_users_with_pagination function to combine user retrieval and birthdate formatting using a list comprehension for cleaner code and enhanced performance.
  3. Refactored get_user_if_contains_username function to use a list comprehension for formatting birthdates, leading to cleaner code and potential performance gains.
  4. Refactored edit_user function to dynamically update user fields using a dictionary and setattr, reducing multiple if statements and improving maintainability.
joaovitoriasilva commented 2 weeks ago

Merged. Thank you again for contributing and sorry it took so long to review and merge it :)

movassaghi6 commented 2 weeks ago

thank you . I try to make better PRs in a better chance .