Challenge Overview
Support getting data directly from the DB bypassing ElasticSearch index (ES).
Project Background
Topcoder Project Service is the main backend service of Topcode Connect – the client-facing application of Topcoder. We have an endpoint that get timelines by “id”. As per Topcoder “v5” API standard, it works the next way:
- first, it tries to get data from the Elastic Seach index using the method “esClient.get”
- but in case it didn’t get any data from the Elastic Search index, it fallbacks to the DB and returns data from DB which is stored in “req.timeline”. Note, that in this endpoint data from the DB has been already retrieved in “validateTimeline.validateTimelineIdParam” and put to “req.timeline”.
So by default this endpoint will return data from ES and only if it cannot find it would return data from DB. We need a way to control it, so we can bypass ES and get data directly from DB.
Technology Stack
-
Node.js
-
PostgreSQL
-
ElasticSearch
Code access
The work for this challenge has to be done in one repository:
- Project Service repo https://github.com/topcoder-platform/tc-project-service branch v5-upgrade commit 203892f8685e32acc9796150447f1c541a384731 or later.
- Config for local setup is provided on the forum.
Individual requirements
-
Add support of “db” query param so if we set it during request we get the data directly from DB and avoid trying to get it from ES. So it would look like this “/v5/timelines/:timelineId?db=true”. Otherwise, the endpoint should work the same as now.
-
Note, that current unit tests for now always calling ES, but cannot find data there and get data from DB.
Add at least 2 unit tests:
- “should return data from ES when ‘db’ param is not set” - check that if ‘db” param is not provided, then data is returned from ES index.
- “should return data from DB without calling ES when ‘db’ param is set” - check that if ‘db’ param is provided, then data is retrieved directly from DB and we don’t call ES at all.
General requirements
-
Existent unit tests should pass. Note, that some unit tests fail randomly when running altogether, so you may run only the unit tests for the files you have changed.
-
Lint should pass.
-
Git patch should be without errors or warnings.
Final Submission Guidelines
-
Git patch.
-
The winner would be required to raise a PR to the repository.