Skip to content

Commit 4074e9b

Browse files
committed
fix: more fixes
1 parent 0aa6f03 commit 4074e9b

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

app/composables/npm/useAlgoliaSearch.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export function useAlgoliaSearch() {
181181

182182
const allHits: AlgoliaHit[] = []
183183
let offset = 0
184+
let serverTotal = 0
184185
const batchSize = 200
185186

186187
// Algolia supports up to 1000 results per query with offset/length pagination
@@ -205,10 +206,11 @@ export function useAlgoliaSearch() {
205206
const response = results[0] as SearchResponse<AlgoliaHit> | undefined
206207
if (!response) break
207208

209+
serverTotal = response.nbHits ?? 0
208210
allHits.push(...response.hits)
209211

210212
// If we got fewer than requested, we've exhausted all results
211-
if (response.hits.length < length || allHits.length >= (response.nbHits ?? 0)) {
213+
if (response.hits.length < length || allHits.length >= serverTotal) {
212214
break
213215
}
214216

@@ -218,7 +220,8 @@ export function useAlgoliaSearch() {
218220
return {
219221
isStale: false,
220222
objects: allHits.map(hitToSearchResult),
221-
total: allHits.length,
223+
// Use server total so callers can detect truncation (allHits.length < total)
224+
total: serverTotal,
222225
time: new Date().toISOString(),
223226
}
224227
}

app/composables/npm/useOrgPackages.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
9898
// --- Algolia fast path ---
9999
if (searchProvider.value === 'algolia') {
100100
try {
101-
return await searchByOwner(org)
101+
const response = await searchByOwner(org)
102+
// If Algolia returns no results, the org may not exist — fall through
103+
// to npm registry path which can properly detect a 404
104+
if (response.objects.length > 0) {
105+
return response
106+
}
102107
} catch {
103108
// Fall through to npm registry path on Algolia failure
104109
}

app/composables/npm/useUserPackages.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,17 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
5757
return emptySearchResponse
5858
}
5959

60-
cache.value = {
61-
username: user,
62-
objects: response.objects,
63-
total: response.total,
60+
// If Algolia returns results, use them. If empty, fall through to npm
61+
// registry which uses `maintainer:` search (matches all maintainers,
62+
// not just the primary owner that Algolia's owner.name indexes).
63+
if (response.objects.length > 0) {
64+
cache.value = {
65+
username: user,
66+
objects: response.objects,
67+
total: response.total,
68+
}
69+
return response
6470
}
65-
return response
6671
} catch {
6772
// Fall through to npm registry path on Algolia failure
6873
}

app/pages/search.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ watch(
492492
493493
// Re-validate suggestions and clear caches when provider changes
494494
watch(isAlgolia, () => {
495+
// Cancel any pending debounced validation from the previous provider
496+
validateSuggestionsDebounced.cancel?.()
495497
// Clear existence cache since results may differ between providers
496498
existenceCache.value = {}
497499
// Re-validate with current query

0 commit comments

Comments
 (0)