From 95185750fb05e82c06d3ddd9e907f06ce66d0317 Mon Sep 17 00:00:00 2001 From: Matthieu Dumont <5095856+Jerska@users.noreply.github.com> Date: Fri, 24 Jun 2022 09:33:05 +0200 Subject: [PATCH] feat(disjunctiveFacetParams): reduce payload size (#912) * feat(dijunctiveFacetParams): reduce payload size This PR reduces the amount of params sent for each disjunctive facet request. It also reduces `hitsPerPage` from `1` to `0`, allowing us to remove the `attributes*` parameters at the same time. This reduces: * the payload sent by a few bytes * and the response size by a few extra bytes as the previous implem sent back one `objectID` per additional request * feat(disjunctiveFacetParams): add responseFields * Update src/requestBuilder.js * chore: remove trailing whitespaces * feat: remove `responseFields` * feat: update unit tests Co-authored-by: Haroen Viaene --- src/requestBuilder.js | 10 +++++----- test/spec/requestBuilder.js | 21 ++++++--------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/requestBuilder.js b/src/requestBuilder.js index c1ac9f25f..504d684a6 100644 --- a/src/requestBuilder.js +++ b/src/requestBuilder.js @@ -118,16 +118,16 @@ var requestBuilder = { var numericFilters = requestBuilder._getNumericFilters(state, facet); var tagFilters = requestBuilder._getTagFilters(state); var additionalParams = { - hitsPerPage: 1, + hitsPerPage: 0, page: 0, - attributesToRetrieve: [], - attributesToHighlight: [], - attributesToSnippet: [], - tagFilters: tagFilters, analytics: false, clickAnalytics: false }; + if (tagFilters.length > 0) { + additionalParams.tagFilters = tagFilters; + } + var hierarchicalFacet = state.getHierarchicalFacetByName(facet); if (hierarchicalFacet) { diff --git a/test/spec/requestBuilder.js b/test/spec/requestBuilder.js index c04a00e79..fc047fbf1 100644 --- a/test/spec/requestBuilder.js +++ b/test/spec/requestBuilder.js @@ -125,44 +125,35 @@ test('orders parameters alphabetically in every query', function() { })); expect(JSON.stringify(queries[1].params)).toBe(JSON.stringify({ analytics: false, - attributesToHighlight: [], attributesToRetrieve: ['this is last in parameters, but first in queries'], - attributesToSnippet: [], clickAnalytics: false, facetFilters: [['whatever:item']], facets: 'test_disjunctive', - hitsPerPage: 1, + hitsPerPage: 0, numericFilters: ['test_numeric>=10'], - page: 0, - tagFilters: '' + page: 0 })); expect(JSON.stringify(queries[2].params)).toBe(JSON.stringify({ analytics: false, - attributesToHighlight: [], attributesToRetrieve: ['this is last in parameters, but first in queries'], - attributesToSnippet: [], clickAnalytics: false, facetFilters: [ ['test_disjunctive:test_disjunctive_value'], ['whatever:item'] ], facets: 'test_numeric', - hitsPerPage: 1, - page: 0, - tagFilters: '' + hitsPerPage: 0, + page: 0 })); expect(JSON.stringify(queries[3].params)).toBe(JSON.stringify({ analytics: false, - attributesToHighlight: [], attributesToRetrieve: ['this is last in parameters, but first in queries'], - attributesToSnippet: [], clickAnalytics: false, facetFilters: [['test_disjunctive:test_disjunctive_value']], facets: ['whatever'], - hitsPerPage: 1, + hitsPerPage: 0, numericFilters: ['test_numeric>=10'], - page: 0, - tagFilters: '' + page: 0 })); });