Skip to content

Commit

Permalink
#145: Add LIMIT filter into /findone endpoints
Browse files Browse the repository at this point in the history
- This helps to make these types of requests more snappy, without impacting the output
  • Loading branch information
MRichards99 committed Oct 9, 2020
1 parent b8534e4 commit 264c130
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion common/icat/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,11 @@ def get_first_result_with_filters(client, table_name, filters):
Using filters in the request, get results of the given entity, but only show the
first one to the user
Since only one result will be outputted, inserting a `PythonICATLimitFilter` in the
query will make Python ICAT's data fetching more snappy and prevent a 500 being
caused by trying to fetch over the number of records limited by ICAT (currently
10000).
:param client: ICAT client containing an authenticated user
:type client: :class:`icat.client.Client`
:param table_name: Table name to extract which entity to use
Expand All @@ -754,14 +759,17 @@ def get_first_result_with_filters(client, table_name, filters):
"Getting only first result of %s, making use of filters in request", table_name
)

limit_filter = PythonICATLimitFilter(1)
filters.append(limit_filter)

entity_data = get_entity_with_filters(
client, table_name, filters, return_first_value_only=True
)

if not entity_data:
raise MissingRecordError("No results found")
else:
return entity_data
return entity_data[0]


def update_entities(client, table_name, data_to_update):
Expand Down

0 comments on commit 264c130

Please sign in to comment.