MCPcopy
hub / github.com/codeaashu/claude-code / getInstallCounts

Function getInstallCounts

src/utils/plugins/installCounts.ts:225–262  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

223 * @returns Map of plugin ID (name@marketplace) to install count, or null if unavailable
224 */
225export async function getInstallCounts(): Promise<Map<string, number> | null> {
226 // Try to load from cache first
227 const cache = await loadInstallCountsCache()
228 if (cache) {
229 logForDebugging('Using cached install counts')
230 logPluginFetch('install_counts', INSTALL_COUNTS_URL, 'cache_hit', 0)
231 const map = new Map<string, number>()
232 for (const entry of cache.counts) {
233 map.set(entry.plugin, entry.unique_installs)
234 }
235 return map
236 }
237
238 // Cache miss or stale - fetch from GitHub
239 try {
240 const counts = await fetchInstallCountsFromGitHub()
241
242 // Save to cache
243 const newCache: InstallCountsCache = {
244 version: INSTALL_COUNTS_CACHE_VERSION,
245 fetchedAt: new Date().toISOString(),
246 counts,
247 }
248 await saveInstallCountsCache(newCache)
249
250 // Convert to Map
251 const map = new Map<string, number>()
252 for (const entry of counts) {
253 map.set(entry.plugin, entry.unique_installs)
254 }
255 return map
256 } catch (error) {
257 // Log error and return null so UI can hide counts
258 logError(error)
259 logForDebugging(`Failed to fetch install counts: ${errorMessage(error)}`)
260 return null
261 }
262}
263
264/**
265 * Format an install count for display.

Callers 3

loadAllPluginsFunction · 0.85
pluginListHandlerFunction · 0.85

Calls 8

loadInstallCountsCacheFunction · 0.85
logForDebuggingFunction · 0.85
logPluginFetchFunction · 0.85
saveInstallCountsCacheFunction · 0.85
logErrorFunction · 0.50
errorMessageFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected