-
Notifications
You must be signed in to change notification settings - Fork 65
Introduce finitePagination setting: remove default fetch of 200 documents #707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,15 @@ module.exports = { | |
'jest-watch-typeahead/filename', | ||
'jest-watch-typeahead/testname', | ||
], | ||
collectCoverage: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I saw the coverage in the CI, you have good coverage in this project, congrats! 🎉 🌮 |
||
coveragePathIgnorePatterns: [ | ||
'cypress/', | ||
'playgrounds/', | ||
'scripts', | ||
'templates', | ||
'tests', | ||
'__tests__', | ||
], | ||
projects: [ | ||
{ | ||
displayName: 'build', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,13 +59,27 @@ export function adaptSearchParams( | |
|
||
const placeholderSearch = searchContext.placeholderSearch | ||
const query = searchContext.query | ||
const paginationTotalHits = searchContext.paginationTotalHits | ||
|
||
// Limit | ||
if ((!placeholderSearch && query === '') || paginationTotalHits === 0) { | ||
// Pagination | ||
const { pagination } = searchContext | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking of a way to reduce the complexity of this function, it seems this accumulated a lot of work in the last additions (and I have a feeling this will keep happening in the future 😬). Maybe there is a way to apply the builder design pattern here, to build the Another way could be create smaller functions which will handle the data as a immutable param and return a new param like with the new composition: // meilisearchParams = {}
meilisearchParams = addAttributesToRetrieve(meilisearchParams)
// meilisearchParams is now {attributesToCrop: [...]}
meilisearchParams = addAttributesToHighlight(meilisearchParams)
// meilisearchParams is now {attributesToCrop: [...], attributesToHighlight: [...]} You could notice that this function is doing a lot because we have comments separating the responsibilities of the function like Another thing I would like to ask is in line 20: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, I didn't find a good reference about a builder pattern in FP but looking at it, I found some good videos about FP in general There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The issue lies with
throwing:
But by saying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the builder pattern I think the adapter pattern is best suited! See #726 |
||
|
||
// Limit based on pagination preferences | ||
if ( | ||
(!placeholderSearch && query === '') || | ||
pagination.paginationTotalHits === 0 | ||
) { | ||
meiliSearchParams.limit = 0 | ||
} else if (searchContext.finitePagination) { | ||
meiliSearchParams.limit = pagination.paginationTotalHits | ||
} else { | ||
meiliSearchParams.limit = paginationTotalHits | ||
const limit = (pagination.page + 1) * pagination.hitsPerPage + 1 | ||
// If the limit is bigger than the total hits accepted | ||
// force the limit to that amount | ||
if (limit > pagination.paginationTotalHits) { | ||
meiliSearchParams.limit = pagination.paginationTotalHits | ||
} else { | ||
meiliSearchParams.limit = limit | ||
} | ||
} | ||
|
||
const sort = searchContext.sort | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { createSearchContext } from './search-context' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.