Skip to content

Commit

Permalink
Make more efficient query (#1958)
Browse files Browse the repository at this point in the history
* feat(version): more efficient query

Note that I blind coded this, so definitely check out in the preview if it works.

reference: https://www.algolia.com/doc/api-reference/api-methods/get-objects/?language=javascript

I also changed the require out for the way smaller `algoliasearch/lite`

* yarn lock

* small fix

* rename var
  • Loading branch information
SaraVieira committed May 22, 2019
1 parent 9338740 commit 4a2cebb
Showing 1 changed file with 3 additions and 3 deletions.
Expand Up @@ -3,7 +3,7 @@ import CrossIcon from 'react-icons/lib/md/clear';
import RefreshIcon from 'react-icons/lib/md/refresh';
import ArrowDropDown from 'react-icons/lib/md/keyboard-arrow-down';
import ArrowDropUp from 'react-icons/lib/md/keyboard-arrow-up';
import algoliasearch from 'algoliasearch';
import algoliasearch from 'algoliasearch/lite';
import compareVersions from 'compare-versions';
import Tooltip from '@codesandbox/common/lib/components/Tooltip';

Expand Down Expand Up @@ -77,8 +77,8 @@ export default class VersionEntry extends React.PureComponent {
'00383ecd8441ead30b1b0ff981c426f5'
);
const index = client.initIndex('npm-search');
index.search({ query: dependency, hitsPerPage: 1 }, (err, { hits }) => {
const versions = Object.keys(hits[0].versions).sort((a, b) => {
index.getObject(dependency, ['versions']).then(({ versions: results }) => {
const versions = Object.keys(results).sort((a, b) => {
try {
return compareVersions(b, a);
} catch (e) {
Expand Down

0 comments on commit 4a2cebb

Please sign in to comment.