API - remove useless user queries
This commit is contained in:
parent
00b6e05805
commit
9e7fbd6eb4
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user