Skip to content

Commit

Permalink
Make /options route only show a maximum of 42 entries
Browse files Browse the repository at this point in the history
Showing too many entries overwhelms the dropdown field in the client.

Therefore, its important to cap the result set at some number, so that the
front-end doesn't freeze up and the user can continue typing to narrow
down the search results.
  • Loading branch information
Stefano Da Ros committed Mar 28, 2019
1 parent e691f3a commit a89794b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/pkg/formatting/jsonForWorkflowAccelerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ func (f *getCollectionAsOptionsFormatter) Format(ctx context.Context, results []
stringify(result.(map[string]interface{})[tableName]),
)
}
formattedResultsSubset := subsetForPerformance(formattedResults)
log.When(config.Options.Logging).Infof(
"[formatter <- asWorkflowType] formattedResult(s): \n%+v ...\n",
formattedResults,
)
JSONResults, err = json.MarshalIndent(&formattedResults, "", " ")
JSONResults, err = json.MarshalIndent(&formattedResultsSubset, "", " ")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -409,6 +410,14 @@ func tableHasRelationships(queryResults map[string]interface{}, table string, fi
func clientWantsDenormalizedResultSet(queryValue string) bool {
return queryValue != ""
}
func subsetForPerformance(in []interface{}) []interface{} {
// To avoid performance issues, return only the first
// 42 results when querying the /options route
if len(in) > 42 {
return in[0:42]
}
return in
}
func withRelationshipFieldsOmitted(table string) (fields []*descriptor.Field) {
typeDescriptor := util.GetTypeDescriptorUsingDBTableName(
config.Options.Descriptor.TypeDescriptors,
Expand Down

0 comments on commit a89794b

Please sign in to comment.