Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
feat(disjunctiveFacetParams): reduce payload size (#912)
Browse files Browse the repository at this point in the history
* 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 <hello@haroen.me>
  • Loading branch information
Jerska and Haroenv committed Jun 24, 2022
1 parent d14ecee commit 9518575
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/requestBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 6 additions & 15 deletions test/spec/requestBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}));
});

Expand Down

0 comments on commit 9518575

Please sign in to comment.