Skip to content

Commit

Permalink
Only call language service when language not defaulted
Browse files Browse the repository at this point in the history
The default language is English, which is also what is stored in
Elasticsearch. Thus, if the user did not specify a language via headers
or query parameter, there is no reason to call Placeholder.

Some Placeholder responses for language translation can be 30KB, and all
that JSON takes considerable time to parse
  • Loading branch information
orangejulius committed Mar 13, 2018
1 parent f5fb04b commit 5d7e228
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions routes/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,18 @@ function addRoutes(app, peliasConfig) {
isAddressItParse
);

const languageWasSpecified = function(req, res) {
return !req.clean.lang.defaulted;
};

// get language adjustments if:
// - there's a response
// - theres's a lang parameter in req.clean
const changeLanguageShouldExecute = all(
hasResponseData,
not(hasRequestErrors),
isChangeLanguageEnabled,
languageWasSpecified,
hasRequestParameter('lang')
);

Expand Down

0 comments on commit 5d7e228

Please sign in to comment.