Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/application/serializers/application_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ def get_query_api_input(self, application, params):
for field in input_field_list:
if field['assignment_method'] == 'api_input' and field['variable'] in params:
query += f"&{field['variable']}={params[field['variable']]}"

if 'asker' in params:
query += f"&asker={params.get('asker')}"
return query

class AccessTokenSerializer(serializers.Serializer):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The provided code snippet does not contain any obvious syntax errors or major issues. However, there is one potential optimization suggestion regarding string formatting methods:

Suggestion for Optimization:
Instead of using multiple += statements to build the query, consider using Python's built-in list comprehension within the join() function, which can simplify and potentially improve performance. Here’s how you could refactor this part of the code:

for field in input_field_list:
    if field['assignment_method'] == 'api_input' and field['variable'] in params:
        # Using join with list compression and f-strings can make it more concise and efficient
        query.append(f"{field['variable']}={params[field['variable']]}")
if 'asker' in params:
    query.append(f"asker={params.get('asker')}")

# Joining the list into a single string separated by '&'
return "&".join(query)

This approach will create a list of strings, then use &.join() to concatenate them efficiently. This method reduces the overhead associated with concatenation operations done by +=, especially when dealing with many fields.

Expand Down