MCPcopy
hub / github.com/ZToolsCenter/ZTools / _getPluginDataStats

Method _getPluginDataStats

src/main/api/shared/database.ts:445–536  ·  view source on GitHub ↗

* 获取所有插件的数据统计(供内部调用)

()

Source from the content-addressed store, hash-verified

443 * 获取所有插件的数据统计(供内部调用)
444 */
445 private async _getPluginDataStats(): Promise<{
446 success: boolean
447 data?: PluginDataRecord[]
448 error?: string
449 }> {
450 try {
451 const allDocs = lmdbInstance.allDocs('PLUGIN/')
452 const pluginStats = new Map<string, { docCount: number; attachmentCount: number }>()
453
454 for (const doc of allDocs) {
455 const match = doc._id.match(/^PLUGIN\/([^/]+)\//)
456 if (match) {
457 const runtimeNamespace = match[1]
458 const stats = pluginStats.get(runtimeNamespace) || { docCount: 0, attachmentCount: 0 }
459 stats.docCount++
460 pluginStats.set(runtimeNamespace, stats)
461 }
462 }
463
464 const attachmentDb = lmdbInstance.getAttachmentDb()
465 const attachmentPrefix = 'attachment-ext:PLUGIN/'
466
467 for (const { key } of attachmentDb.getRange({
468 start: attachmentPrefix,
469 end: this.getNextPrefix(attachmentPrefix)
470 })) {
471 // 双重检查:确保 key 完全匹配前缀
472 if (key.startsWith(attachmentPrefix)) {
473 const match = key.match(/^attachment-ext:PLUGIN\/([^/]+)\//)
474 if (match) {
475 const runtimeNamespace = match[1]
476 const stats = pluginStats.get(runtimeNamespace) || { docCount: 0, attachmentCount: 0 }
477 stats.attachmentCount++
478 pluginStats.set(runtimeNamespace, stats)
479 }
480 }
481 }
482
483 const pluginsDoc = lmdbInstance.get('ZTOOLS/plugins')
484 const plugins = pluginsDoc?.data || []
485 const pluginsByName = new Map<string, any>()
486 for (const plugin of plugins) {
487 if (!plugin?.name) continue
488 pluginsByName.set(plugin.name, plugin)
489 }
490
491 const data = Array.from(pluginStats.entries()).map(([pluginName, stats]) => {
492 const plugin = pluginsByName.get(pluginName)
493 return {
494 pluginName,
495 pluginTitle: plugin?.title || null,
496 docCount: stats.docCount,
497 attachmentCount: stats.attachmentCount,
498 logo: plugin?.logo || null,
499 isDevelopment: isDevelopmentPluginName(pluginName)
500 } satisfies PluginDataRecord
501 })
502

Callers 2

setupIPCMethod · 0.95
getPluginDataStatsMethod · 0.95

Calls 6

getNextPrefixMethod · 0.95
isDevelopmentPluginNameFunction · 0.90
getAttachmentDbMethod · 0.80
getRangeMethod · 0.80
getMethod · 0.65
allDocsMethod · 0.45

Tested by

no test coverage detected