Skip to content

Commit d195730

Browse files
authored
Merge pull request #615 from topcoder-platform/fix/search
fix: search
2 parents f8698e7 + 80eabba commit d195730

File tree

4 files changed

+20
-40
lines changed

4 files changed

+20
-40
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ workflows:
8383
branches:
8484
only:
8585
- dev
86-
- fix/schema
86+
- fix/search
8787

8888
- "build-qa":
8989
context: org-global
9090
filters:
9191
branches:
9292
only:
93-
- refactor/domain-challenge
93+
- qa
9494

9595
# Production builds are exectuted only on tagged commits to the
9696
# master branch.

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ Dev: [![CircleCI](https://circleci.com/gh/topcoder-platform/challenge-api/tree/d
2222

2323
- [Resources API](https://github.com/topcoder-platform/resources-api)
2424
- [ES Processor](https://github.com/topcoder-platform/challenge-processor-es) - Updates data in ElasticSearch
25-
- [Legacy Processor](https://github.com/topcoder-platform/legacy-challenge-processor) - Moves data from DynamoDB back to Informix
26-
- [Legacy Migration Script](https://github.com/topcoder-platform/legacy-challenge-migration-script) - Moves data from Informix to DynamoDB
27-
- [Frontend App](https://github.com/topcoder-platform/challenge-engine-ui)
25+
- [Domain Challenge](https://github.com/topcoder-platform/domain-challenge) - Domain Challenge
2826

2927
## Prerequisites
3028

31-
- [NodeJS](https://nodejs.org/en/) (v10)
29+
- [NodeJS](https://nodejs.org/en/) (v18+)
3230
- [AWS S3](https://aws.amazon.com/s3/)
3331
- [Elasticsearch v6](https://www.elastic.co/)
3432
- [Docker](https://www.docker.com/)

src/common/helper.js

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -754,36 +754,21 @@ function calculateChallengeEndDate(challenge, data) {
754754
async function listChallengesByMember(memberId) {
755755
const token = await m2mHelper.getM2MToken();
756756
let allIds = [];
757-
// get search is paginated, we need to get all pages' data
758-
let page = 1;
759-
while (true) {
760-
let result = {};
761-
try {
762-
result = await axios.get(`${config.RESOURCES_API_URL}/${memberId}/challenges`, {
763-
headers: { Authorization: `Bearer ${token}` },
764-
params: {
765-
page,
766-
perPage: 10000,
767-
},
768-
});
769-
} catch (e) {
770-
// only log the error but don't throw it, so the following logic can still be executed.
771-
logger.debug(`Failed to get challenges that accessible to the memberId ${memberId}`, e);
772-
}
773-
const ids = result.data || [];
774-
if (ids.length === 0) {
775-
break;
776-
}
777-
allIds = allIds.concat(ids);
778-
page += 1;
779-
if (
780-
result.headers &&
781-
result.headers["x-total-pages"] &&
782-
page > Number(result.headers["x-total-pages"])
783-
) {
784-
break;
785-
}
757+
758+
try {
759+
const result = await axios.get(`${config.RESOURCES_API_URL}/${memberId}/challenges`, {
760+
headers: { Authorization: `Bearer ${token}` },
761+
params: {
762+
useScroll: true,
763+
},
764+
});
765+
766+
allIds = result.data || [];
767+
} catch (e) {
768+
// only log the error but don't throw it, so the following logic can still be executed.
769+
logger.debug(`Failed to get challenges that accessible to the memberId ${memberId}`, e);
786770
}
771+
787772
return allIds;
788773
}
789774

src/services/ChallengeService.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ async function searchChallenges(currentUser, criteria) {
149149
_.includes(config.SELF_SERVICE_WHITELIST_HANDLES, currentUser.handle.toLowerCase()));
150150

151151
const includedTrackIds = _.isArray(criteria.trackIds) ? criteria.trackIds : [];
152-
153152
const includedTypeIds = _.isArray(criteria.typeIds) ? criteria.typeIds : [];
154153

155154
if (criteria.type) {
@@ -168,7 +167,6 @@ async function searchChallenges(currentUser, criteria) {
168167
criteria.trackId = _.get(trackSearchRes, "result[0].id");
169168
}
170169
}
171-
172170
if (criteria.types) {
173171
for (const t of criteria.types) {
174172
const typeSearchRes = await ChallengeTypeService.searchChallengeTypes({ abbreviation: t });
@@ -187,7 +185,6 @@ async function searchChallenges(currentUser, criteria) {
187185
}
188186
}
189187
}
190-
191188
if (criteria.typeId) {
192189
includedTypeIds.push(criteria.typeId);
193190
}
@@ -604,10 +601,10 @@ async function searchChallenges(currentUser, criteria) {
604601
match_phrase: { "task.isAssigned": criteria.taskIsAssigned },
605602
});
606603
}
607-
if (criteria.taskMemberId || criteria.memberId) {
604+
if (criteria.taskMemberId) {
608605
boolQuery.push({
609606
match_phrase: {
610-
"task.memberId": criteria.taskMemberId || criteria.memberId,
607+
"task.memberId": criteria.taskMemberId,
611608
},
612609
});
613610
}

0 commit comments

Comments
 (0)