Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 56f7021

Browse files
committed
Speed up search by avoiding apm overhead
1 parent 483a86c commit 56f7021

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

lib/atom-io-client.coffee

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,31 @@ class AtomIoClient
187187

188188
getCachePath: ->
189189
@cachePath ?= path.join(remote.app.getPath('userData'), 'Cache', 'settings-view')
190+
191+
search: (query, type, callback) ->
192+
qs = {q: query}
193+
194+
if type is 'packages'
195+
qs.filter = 'package'
196+
else if type is 'themes'
197+
qs.filter = 'theme'
198+
199+
options = {
200+
url: "#{@baseURL}packages/search"
201+
headers: {'User-Agent': navigator.userAgent}
202+
qs: qs
203+
}
204+
205+
new Promise (resolve, reject) ->
206+
request options, (err, res, body) ->
207+
if err
208+
reject err
209+
else
210+
try
211+
resolve JSON.parse body
212+
.filter (pack) -> pack.releases?.latest?
213+
.map ({readme, metadata, downloads, stargazers_count}) ->
214+
Object.assign metadata, {readme, downloads, stargazers_count}
215+
.sort (a, b) -> b.downloads - a.downloads
216+
catch error
217+
reject error

lib/install-panel.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,8 @@ export default class InstallPanel {
206206
this.refs.searchMessage.textContent = `Searching ${this.searchType} for \u201C${query}\u201D\u2026`
207207
this.refs.searchMessage.style.display = ''
208208

209-
const opts = {}
210-
opts[this.searchType] = true
211-
opts['sortBy'] = 'downloads'
212-
213209
try {
214-
let packages = (await this.packageManager.search(query, opts)) || []
210+
const packages = (await this.client.search(query, this.searchType)) || []
215211
this.refs.resultsContainer.innerHTML = ''
216212
this.refs.searchMessage.style.display = 'none'
217213
if (packages.length === 0) {

spec/install-panel-spec.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe 'InstallPanel', ->
6060

6161
describe "searching packages", ->
6262
it "highlights exact name matches", ->
63-
spyOn(@packageManager, 'search').andCallFake ->
63+
spyOn(@panel.client, 'search').andCallFake ->
6464
new Promise (resolve, reject) -> resolve([ {name: 'not-first'}, {name: 'first'} ])
6565
spyOn(@panel, 'getPackageCardView').andCallThrough()
6666

@@ -72,7 +72,7 @@ describe 'InstallPanel', ->
7272
expect(@panel.getPackageCardView.argsForCall[1][0].name).toEqual 'not-first'
7373

7474
it "prioritizes partial name matches", ->
75-
spyOn(@packageManager, 'search').andCallFake ->
75+
spyOn(@panel.client, 'search').andCallFake ->
7676
new Promise (resolve, reject) -> resolve([ {name: 'something else'}, {name: 'partial name match'} ])
7777
spyOn(@panel, 'getPackageCardView').andCallThrough()
7878

0 commit comments

Comments
 (0)