Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
PORT: process.env.PORT || 3000,
API_VERSION: process.env.API_VERSION || 'v5',
DEFAULT_PAGE_SIZE: process.env.DEFAULT_PAGE_SIZE || 1000,
MAX_ELASTIC_SEARCH_RECORDS_SIZE: process.env.MAX_ELASTIC_SEARCH_RECORDS_SIZE || 10000,
// used to properly set the header response to api calls for services behind a load balancer
API_BASE_URL: process.env.API_BASE_URL || `http://localhost:3000`,

Expand Down
18 changes: 17 additions & 1 deletion src/services/ResourceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,23 @@ async function listChallengesByMember (memberId, criteria) {
}
})

const docs = await searchES(mustQuery, perPage, page)
let docs = {
hits: {
total: 0,
hits: []
}
}

if (perPage * page <= config.MAX_ELASTIC_SEARCH_RECORDS_SIZE) {
docs = await searchES(mustQuery, perPage, page)
} else {
throw new errors.BadRequestError(`
ES pagination params:
page ${page},
perPage: ${perPage}
exceeds the max search window:${config.MAX_ELASTIC_SEARCH_RECORDS_SIZE}`
)
}

// Extract data from hits
let result = _.map(docs.hits.hits, item => item._source)
Expand Down