Skip to content

Commit 8622060

Browse files
Merge pull request #104 from topcoder-platform/fix-listmemberchallenges
Fix listmemberchallenges
2 parents 6f25a14 + 98f0666 commit 8622060

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

config/default.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
PORT: process.env.PORT || 3000,
88
API_VERSION: process.env.API_VERSION || 'v5',
99
DEFAULT_PAGE_SIZE: process.env.DEFAULT_PAGE_SIZE || 1000,
10+
MAX_ELASTIC_SEARCH_RECORDS_SIZE: process.env.MAX_ELASTIC_SEARCH_RECORDS_SIZE || 10000,
1011
// used to properly set the header response to api calls for services behind a load balancer
1112
API_BASE_URL: process.env.API_BASE_URL || `http://localhost:3000`,
1213

src/services/ResourceService.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,23 @@ async function listChallengesByMember (memberId, criteria) {
446446
}
447447
})
448448

449-
const docs = await searchES(mustQuery, perPage, page)
449+
let docs = {
450+
hits: {
451+
total: 0,
452+
hits: []
453+
}
454+
}
455+
456+
if (perPage * page <= config.MAX_ELASTIC_SEARCH_RECORDS_SIZE) {
457+
docs = await searchES(mustQuery, perPage, page)
458+
} else {
459+
throw new errors.BadRequestError(`
460+
ES pagination params:
461+
page ${page},
462+
perPage: ${perPage}
463+
exceeds the max search window:${config.MAX_ELASTIC_SEARCH_RECORDS_SIZE}`
464+
)
465+
}
450466

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

0 commit comments

Comments
 (0)