From 9e7fbd6eb4e31d12336887fee4276fe7651a0d5e Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 1 Dec 2021 19:31:42 +0100 Subject: [PATCH] API - remove useless user queries --- fittrackee/tests/workouts/test_gpx_utils.py | 4 ++-- fittrackee/users/utils.py | 8 -------- fittrackee/workouts/utils.py | 15 +++++++-------- fittrackee/workouts/workouts.py | 2 +- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/fittrackee/tests/workouts/test_gpx_utils.py b/fittrackee/tests/workouts/test_gpx_utils.py index 7c80d5de..df5da68c 100644 --- a/fittrackee/tests/workouts/test_gpx_utils.py +++ b/fittrackee/tests/workouts/test_gpx_utils.py @@ -46,7 +46,7 @@ class TestStoppedSpeedThreshold: ) as gpx_track_segment_mock: process_files( - auth_user_id=user_1.id, + auth_user=user_1, folders=folders, workout_data={'sport_id': sport_id}, workout_file=gpx_file_storage, @@ -76,7 +76,7 @@ class TestStoppedSpeedThreshold: ) as gpx_track_segment_mock: process_files( - auth_user_id=user_1.id, + auth_user=user_1, folders=folders, workout_data={'sport_id': sport_1_cycling.id}, workout_file=gpx_file_storage, diff --git a/fittrackee/users/utils.py b/fittrackee/users/utils.py index 6f6a1984..cd881874 100644 --- a/fittrackee/users/utils.py +++ b/fittrackee/users/utils.py @@ -12,14 +12,6 @@ from fittrackee.responses import ( from .models import User -def is_admin(user_id: int) -> bool: - """ - Return if user has admin rights - """ - user = User.query.filter_by(id=user_id).first() - return user.admin - - def is_valid_email(email: str) -> bool: """ Return if email format is valid diff --git a/fittrackee/workouts/utils.py b/fittrackee/workouts/utils.py index 95488cbf..015b825b 100644 --- a/fittrackee/workouts/utils.py +++ b/fittrackee/workouts/utils.py @@ -299,9 +299,9 @@ def process_one_gpx_file( gpx_data, map_data, weather_data = get_gpx_info( params['file_path'], stopped_speed_threshold ) - auth_user_id = params['user'].id + auth_user = params['auth_user'] new_filepath = get_new_file_path( - auth_user_id=auth_user_id, + auth_user_id=auth_user.id, workout_date=gpx_data['start'], old_filename=filename, sport=params['sport_label'], @@ -311,7 +311,7 @@ def process_one_gpx_file( gpx_data['filename'] = new_filepath map_filepath = get_new_file_path( - auth_user_id=auth_user_id, + auth_user_id=auth_user.id, workout_date=gpx_data['start'], extension='.png', sport=params['sport_label'], @@ -325,7 +325,7 @@ def process_one_gpx_file( try: new_workout = create_workout( - params['user'], params['workout_data'], gpx_data + auth_user, params['workout_data'], gpx_data ) new_workout.map = map_filepath new_workout.map_id = get_map_hash(map_filepath) @@ -380,7 +380,7 @@ def process_zip_archive( def process_files( - auth_user_id: int, + auth_user: User, workout_data: Dict, workout_file: FileStorage, folders: Dict, @@ -399,9 +399,8 @@ def process_files( 'error', f"Sport id: {workout_data.get('sport_id')} does not exist", ) - user = User.query.filter_by(id=auth_user_id).first() sport_preferences = UserSportPreference.query.filter_by( - user_id=user.id, sport_id=sport.id + user_id=auth_user.id, sport_id=sport.id ).first() stopped_speed_threshold = ( sport.stopped_speed_threshold @@ -410,7 +409,7 @@ def process_files( ) common_params = { - 'user': user, + 'auth_user': auth_user, 'workout_data': workout_data, 'file_path': file_path, 'sport_label': sport.label, diff --git a/fittrackee/workouts/workouts.py b/fittrackee/workouts/workouts.py index 192e7217..e0828c11 100644 --- a/fittrackee/workouts/workouts.py +++ b/fittrackee/workouts/workouts.py @@ -980,7 +980,7 @@ def post_workout(auth_user: User) -> Union[Tuple[Dict, int], HttpResponse]: try: new_workouts = process_files( - auth_user.id, workout_data, workout_file, folders + auth_user, workout_data, workout_file, folders ) if len(new_workouts) > 0: response_object = {