Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Commit

Permalink
[#474] Improve /search endpoint performance
Browse files Browse the repository at this point in the history
Using `res.json()` calls to `JSON.stringify()` on the response. As we're
getting the response from ElasticSearch, all fields are already converted to
JSON (there're no Date classes, for example), so there's no need to call
`JSON.stringify()`.

That reduces the response time in about 50%. You can check by using:
  ab -n 1000 -c 50 http://localhost:10010/v1/search

With and without this patch.

opentrials/opentrials#474
  • Loading branch information
vitorbaptista committed Oct 6, 2016
1 parent e832224 commit 42ef133
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ function searchTrials(req, res) {

return client.search(searchQuery)
.then(_convertElasticSearchResult)
.then(res.json)
.then((data) => {
res.status(200);
res.setHeader('Content-Type', 'application/json');
return res.end(data);
})
.catch((err) => {
res.finish();
throw err;
Expand Down

0 comments on commit 42ef133

Please sign in to comment.