Skip to content

Commit

Permalink
Merge pull request #75 from tom0827/EPICSYSTEM-61
Browse files Browse the repository at this point in the history
Epicsystem 61: survey load times
  • Loading branch information
tom0827 authored Jul 12, 2024
2 parents cf9dec5 + 1f8e621 commit 48f98f7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
3 changes: 3 additions & 0 deletions met-api/src/met_api/resources/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ def get():
published_date_to=args.get('published_date_to', None, type=str),
)

reduce_data = args.get('reduce_data', default=False, type=lambda v: v.lower() == 'true')

survey_records = SurveyService()\
.get_surveys_paginated(
user_id,
pagination_options,
search_options,
reduce_data,
)
return survey_records, HTTPStatus.OK
except ValueError as err:
Expand Down
9 changes: 7 additions & 2 deletions met-api/src/met_api/services/survey_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_open(cls, survey_id):
return survey

@staticmethod
def get_surveys_paginated(user_id, pagination_options: PaginationOptions, search_options: SurveySearchOptions):
def get_surveys_paginated(user_id, pagination_options: PaginationOptions, search_options: SurveySearchOptions, reduce_data: bool):
"""Get engagements paginated."""
# check if user has view all surveys access to view hidden surveys as well
user_roles = TokenInfo.get_user_roles()
Expand All @@ -87,7 +87,12 @@ def get_surveys_paginated(user_id, pagination_options: PaginationOptions, search
pagination_options,
search_options,
)
surveys_schema = SurveySchema(many=True)
# surveys_schema = ReducedSurveySchema(many=True) if reduced_data else SurveySchema(many=True)

if reduce_data:
surveys_schema = SurveySchema(many=True, only=("id", "name"))
else:
surveys_schema = SurveySchema(many=True)

return {
'items': surveys_schema.dump(items),
Expand Down
23 changes: 13 additions & 10 deletions met-web/src/components/survey/create/OptionsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ const OptionsForm = () => {

const handleFetchSurveys = async () => {
try {
const fetchedLinkableSurveys = await fetchSurveys({
is_unlinked: true,
exclude_hidden: true,
exclude_template: true,
});
setAvailableLinkSurveys(fetchedLinkableSurveys);

const fetchedClonableSurveys = await fetchSurveys({
exclude_hidden: true,
});
const [fetchedLinkableSurveys, fetchedClonableSurveys] = await Promise.all([
fetchSurveys({
is_unlinked: true,
exclude_hidden: true,
exclude_template: true,
reduce_data: true,
}),
fetchSurveys({
exclude_hidden: true,
reduce_data: true,
}),
]);

setAvailableLinkSurveys(fetchedLinkableSurveys);
setAvailableCloneSurveys(fetchedClonableSurveys);
setLoadingSurveys(false);
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions met-web/src/services/surveyService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface FetchSurveyParams {
is_unlinked?: boolean;
exclude_hidden?: boolean;
exclude_template?: boolean;
reduce_data?: boolean;
}
export const fetchSurveys = async (params: FetchSurveyParams = {}): Promise<Survey[]> => {
const responseData = await http.GetRequest<Page<Survey>>(Endpoints.Survey.GET_LIST, { ...params });
Expand Down

0 comments on commit 48f98f7

Please sign in to comment.