Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fa6c590
fix: org page fetching metadata at once
Adebesin-Cell Mar 5, 2026
824cba3
Merge branch 'main' into fix/org
Adebesin-Cell Mar 17, 2026
6e49401
feat: progressive loading for org packages
Adebesin-Cell Mar 17, 2026
3d53a70
Merge branch 'main' into fix/org
Adebesin-Cell Mar 18, 2026
8e5b116
Merge branch 'main' into fix/org
serhalp Apr 6, 2026
5686329
Merge branch 'main' into fix/org
ghostdevv Apr 9, 2026
89edc2b
refactor: use extended useVisibleItems for progressive org loading
Adebesin-Cell Apr 9, 2026
44cc1c2
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 13, 2026
611ecc6
Merge branch 'main' into fix/org
Adebesin-Cell Apr 13, 2026
7082536
fix: track remaining packages by name and support partial expand
Adebesin-Cell Apr 13, 2026
21ecd99
chore: remove accidentally committed config files
Adebesin-Cell Apr 13, 2026
c99df23
fix: show load-more when server has unfetched packages
Adebesin-Cell Apr 13, 2026
686ad04
refactor: progressive org loading with incremental batches
Adebesin-Cell Apr 13, 2026
f91feb3
fix: remove unnecessary quotes around org name in i18n message
Adebesin-Cell Apr 13, 2026
7e0f14c
Merge branch 'main' into fix/org
Adebesin-Cell Apr 13, 2026
68fe83b
Merge branch 'main' into fix/org
Adebesin-Cell Apr 14, 2026
91aaf01
fix: persist allPackageNames in Nuxt payload for client hydration
Adebesin-Cell Apr 14, 2026
2f85269
fix: batch Algolia getObjects requests for large orgs
Adebesin-Cell Apr 14, 2026
e22bd3c
fix: avoid spread into push for large batch results
Adebesin-Cell Apr 15, 2026
16dc489
Merge branch 'main' into fix/org
Adebesin-Cell Apr 15, 2026
b72db1f
Merge branch 'main' into fix/org
Adebesin-Cell Apr 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions app/composables/npm/useAlgoliaSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,9 @@ export function useAlgoliaSearch() {
}
}

/** Fetch metadata for specific packages by exact name using Algolia's getObjects API. */
async function getPackagesByName(packageNames: string[]): Promise<NpmSearchResponse> {
if (packageNames.length === 0) {
return { isStale: false, objects: [], total: 0, time: new Date().toISOString() }
}
/** Fetch metadata for a single batch of packages (max 1000) by exact name. */
async function getPackagesByNameSlice(names: string[]): Promise<NpmSearchResult[]> {
if (names.length === 0) return []

const response = await $fetch<{ results: (AlgoliaHit | null)[] }>(
`https://${algolia.appId}-dsn.algolia.net/1/indexes/*/objects`,
Expand All @@ -229,7 +227,7 @@ export function useAlgoliaSearch() {
'x-algolia-application-id': algolia.appId,
},
body: {
requests: packageNames.map(name => ({
requests: names.map(name => ({
indexName,
objectID: name,
attributesToRetrieve: ATTRIBUTES_TO_RETRIEVE,
Expand All @@ -238,11 +236,41 @@ export function useAlgoliaSearch() {
},
)

const hits = response.results.filter((r): r is AlgoliaHit => r !== null && 'name' in r)
return response.results
.filter((r): r is AlgoliaHit => r !== null && 'name' in r)
.map(hitToSearchResult)
}

/** Fetch metadata for specific packages by exact name using Algolia's getObjects API. */
async function getPackagesByName(packageNames: string[]): Promise<NpmSearchResponse> {
if (packageNames.length === 0) {
return { isStale: false, objects: [], total: 0, time: new Date().toISOString() }
}

// Algolia getObjects has a limit of 1000 objects per request, so batch if needed
const BATCH_SIZE = 1000
const batches: string[][] = []
for (let i = 0; i < packageNames.length; i += BATCH_SIZE) {
batches.push(packageNames.slice(i, i + BATCH_SIZE))
}

// Fetch batches with concurrency limit to avoid overwhelming the API
const CONCURRENCY = 3
const allObjects: NpmSearchResult[] = []
for (let i = 0; i < batches.length; i += CONCURRENCY) {
const chunk = batches.slice(i, i + CONCURRENCY)
const results = await Promise.all(chunk.map(batch => getPackagesByNameSlice(batch)))
for (const result of results) {
for (const pkg of result) {
allObjects.push(pkg)
}
}
}

return {
isStale: false,
objects: hits.map(hitToSearchResult),
total: hits.length,
objects: allObjects,
total: allObjects.length,
time: new Date().toISOString(),
}
}
Expand Down
13 changes: 9 additions & 4 deletions app/composables/npm/useOrgPackages.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type { NpmSearchResponse, NpmSearchResult, PackageMetaResponse } from '#shared/types'
import { emptySearchResponse, metaToSearchResult } from './search-utils'
import { mapWithConcurrency } from '#shared/utils/async'

/**
* Fetch all packages for an npm organization.
*
* 1. Gets the authoritative package list from the npm registry (single request)
* 2. Fetches metadata from Algolia by exact name (single request)
* 2. Fetches metadata from Algolia by exact name (batched, max 1000 per request)
* 3. Falls back to lightweight server-side package-meta lookups
*/
export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
Expand Down Expand Up @@ -32,7 +36,6 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
)
packageNames = packages
} catch (err) {
// Check if this is a 404 (org not found)
if (err && typeof err === 'object' && 'statusCode' in err && err.statusCode === 404) {
const error = createError({
statusCode: 404,
Expand All @@ -44,15 +47,14 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
}
throw error
}
// For other errors (network, etc.), return empty array to be safe
packageNames = []
}

if (packageNames.length === 0) {
return emptySearchResponse()
}

// Fetch metadata + downloads from Algolia (single request via getObjects)
// Fetch metadata from Algolia (batched in chunks of 1000, parallel)
if (searchProviderValue.value === 'algolia') {
try {
const response = await getPackagesByName(packageNames)
Expand All @@ -64,6 +66,9 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
}
}

// Staleness guard
if (toValue(orgName) !== org) return emptySearchResponse()

// npm fallback: fetch lightweight metadata via server proxy
const metaResults = await mapWithConcurrency(
packageNames,
Expand Down
2 changes: 1 addition & 1 deletion i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@
"failed_to_load": "Failed to load organization packages",
"no_match": "No packages match \"{query}\"",
"not_found": "Organization not found",
"not_found_message": "The organization \"{'@'}{name}\" does not exist on npm"
"not_found_message": "The organization {'@'}{name} does not exist on npm"
}
},
"user": {
Expand Down
Loading