From 7d9e3e29fd49ebdd3aa24d6e6484d7889d352b06 Mon Sep 17 00:00:00 2001 From: Joxit Date: Sun, 26 Aug 2018 23:31:44 +0200 Subject: [PATCH] feat(findbyid): Add lang query param for placeholder This will reduce network transfer and speedup requests Related: https://github.com/pelias/placeholder/pull/128 --- service/configurations/Language.js | 10 ++++++++-- test/unit/service/configurations/Language.js | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/service/configurations/Language.js b/service/configurations/Language.js index c20fa861..a4d96c96 100644 --- a/service/configurations/Language.js +++ b/service/configurations/Language.js @@ -15,12 +15,18 @@ class Language extends ServiceConfiguration { Array.prototype.push.apply(acc, _.values(_.pickBy(doc.parent, (v, k) => _.endsWith(k, '_id') ) ) ); return acc; }, []); - - return { + const lang = _.get(req, 'clean.lang.iso6393'); + const parameters = { // arrays will be nested, so flatten first, then uniqify, and finally join elements with comma ids: _.uniq(_.flattenDeep(ids)).join(',') }; + if (lang) { + parameters.lang = lang; + } + + return parameters; + } getUrl(req) { diff --git a/test/unit/service/configurations/Language.js b/test/unit/service/configurations/Language.js index 72cfb7d3..682ddc0a 100644 --- a/test/unit/service/configurations/Language.js +++ b/test/unit/service/configurations/Language.js @@ -117,6 +117,24 @@ module.exports.tests.all = (test, common) => { }); + + test('getParameters should return lang when req.clean.lang.iso6393 is defined', (t) => { + const configBlob = { + url: 'http://localhost:1234', + timeout: 17, + retries: 19 + }; + + const req = {clean: {lang: {iso6393: 'eng' }}}; + const res = { }; + + const language = new Language(configBlob); + + t.deepEquals(language.getParameters(req, res), { ids: '', lang: 'eng' }); + t.end(); + + }); + test('getHeaders should return empty object', (t) => { const configBlob = { url: 'base url',