Skip to content

Commit 1685e46

Browse files
committed
fix: prevent duplicate api calls & installedPacksWithVersions instead of installpackids
1 parent 5d6de3a commit 1685e46

File tree

3 files changed

+46
-33
lines changed

3 files changed

+46
-33
lines changed

src/composables/nodePack/useInstalledPacks.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { whenever } from '@vueuse/core'
2-
import { computed, onUnmounted } from 'vue'
2+
import { computed, onUnmounted, ref } from 'vue'
33

44
import { useNodePacks } from '@/composables/nodePack/useNodePacks'
55
import { useComfyManagerStore } from '@/stores/comfyManagerStore'
@@ -9,6 +9,10 @@ import type { components } from '@/types/comfyRegistryTypes'
99
export const useInstalledPacks = (options: UseNodePacksOptions = {}) => {
1010
const comfyManagerStore = useComfyManagerStore()
1111

12+
// Flag to prevent duplicate fetches during initialization
13+
const isInitializing = ref(false)
14+
const lastFetchedIds = ref<string>('')
15+
1216
const installedPackIds = computed(() =>
1317
Array.from(comfyManagerStore.installedPacksIds)
1418
)
@@ -20,15 +24,30 @@ export const useInstalledPacks = (options: UseNodePacksOptions = {}) => {
2024
packs.filter((pack) => comfyManagerStore.isPackInstalled(pack.id))
2125

2226
const startFetchInstalled = async () => {
23-
if (comfyManagerStore.installedPacksIds.size === 0) {
24-
await comfyManagerStore.refreshInstalledList()
27+
// Prevent duplicate calls during initialization
28+
if (isInitializing.value) {
29+
return
30+
}
31+
32+
isInitializing.value = true
33+
try {
34+
if (comfyManagerStore.installedPacksIds.size === 0) {
35+
await comfyManagerStore.refreshInstalledList()
36+
}
37+
await startFetch()
38+
} finally {
39+
isInitializing.value = false
2540
}
26-
await startFetch()
2741
}
2842

2943
// When installedPackIds changes, we need to update the nodePacks
30-
whenever(installedPackIds, async () => {
31-
await startFetch()
44+
// But only if the IDs actually changed (not just array reference)
45+
whenever(installedPackIds, async (newIds) => {
46+
const newIdsStr = newIds.sort().join(',')
47+
if (newIdsStr !== lastFetchedIds.value && !isInitializing.value) {
48+
lastFetchedIds.value = newIdsStr
49+
await startFetch()
50+
}
3251
})
3352

3453
onUnmounted(() => {

src/composables/useConflictDetection.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,25 @@ export function useConflictDetection() {
246246
// Step 5: Combine local installation data with Registry version data
247247
const requirements: NodePackRequirements[] = []
248248

249-
// Create a map for quick access to version info
250-
const versionInfoMap = new Map(
251-
installedPacksWithVersions.value.map((pack) => [pack.id, pack.version])
252-
)
253-
254-
for (const pack of installedPacks.value) {
255-
const packageId = pack.id || ''
249+
// IMPORTANT: Use installedPacksWithVersions to check ALL installed packages
250+
// not just the ones that exist in Registry (installedPacks)
251+
for (const installedPack of installedPacksWithVersions.value) {
252+
const packageId = installedPack.id
256253
const versionData = versionDataMap.get(packageId)
257-
const installedVersion = versionInfoMap.get(packageId) || 'unknown'
254+
const installedVersion = installedPack.version || 'unknown'
258255

259256
// Check if package is enabled using store method
260257
const isEnabled = managerStore.isPackEnabled(packageId)
261258

259+
// Find the pack info from Registry if available
260+
const packInfo = installedPacks.value.find((p) => p.id === packageId)
261+
262262
if (versionData) {
263263
// Combine local installation data with version-specific Registry data
264264
const requirement: NodePackRequirements = {
265265
// Basic package info
266-
id: pack.id,
267-
name: pack.name,
266+
id: packageId,
267+
name: packInfo?.name || packageId,
268268
installed_version: installedVersion,
269269
is_enabled: isEnabled,
270270

@@ -289,8 +289,8 @@ export function useConflictDetection() {
289289

290290
// Create fallback requirement without Registry data
291291
const fallbackRequirement: NodePackRequirements = {
292-
id: pack.id,
293-
name: pack.name,
292+
id: packageId,
293+
name: packInfo?.name || packageId,
294294
installed_version: installedVersion,
295295
is_enabled: isEnabled,
296296
is_banned: false,
@@ -400,19 +400,19 @@ export function useConflictDetection() {
400400
try {
401401
const comfyManagerService = useComfyManagerService()
402402

403-
// Use installed packs from useInstalledPacks composable
403+
// Use installedPacksWithVersions to match what versions bulk API uses
404+
// This ensures both APIs check the same set of packages
404405
if (
405-
!installedPacksReady.value ||
406-
!installedPacks.value ||
407-
installedPacks.value.length === 0
406+
!installedPacksWithVersions.value ||
407+
installedPacksWithVersions.value.length === 0
408408
) {
409409
console.warn(
410-
'[ConflictDetection] No installed packages available from useInstalledPacks'
410+
'[ConflictDetection] No installed packages available for import failure check'
411411
)
412412
return {}
413413
}
414414

415-
const packageIds = installedPacks.value.map((pack) => pack.id || '')
415+
const packageIds = installedPacksWithVersions.value.map((pack) => pack.id)
416416

417417
// Use bulk API to get import failure info for all packages at once
418418
const bulkResult = await comfyManagerService.getImportFailInfoBulk(
@@ -544,10 +544,6 @@ export function useConflictDetection() {
544544
// 4. Detect Python import failures
545545
const importFailInfo = await fetchImportFailInfo()
546546
const importFailResults = detectImportFailConflicts(importFailInfo)
547-
console.log(
548-
'[ConflictDetection] Python import failures detected:',
549-
importFailResults
550-
)
551547

552548
// 5. Combine all results
553549
const allResults = [...packageResults, ...importFailResults]
@@ -636,9 +632,12 @@ export function useConflictDetection() {
636632
/**
637633
* Error-resilient initialization (called on app mount).
638634
* Async function that doesn't block UI setup.
635+
* Ensures proper order: installed -> system_stats -> versions bulk -> import_fail_info_bulk
639636
*/
640637
async function initializeConflictDetection(): Promise<void> {
641638
try {
639+
// Simply perform conflict detection
640+
// The useInstalledPacks will handle fetching installed list if needed
642641
await performConflictDetection()
643642
} catch (error) {
644643
console.warn(

src/stores/comfyManagerStore.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { ref, watch } from 'vue'
55
import { useI18n } from 'vue-i18n'
66

77
import { useCachedRequest } from '@/composables/useCachedRequest'
8-
import { useConflictDetection } from '@/composables/useConflictDetection'
98
import { useManagerQueue } from '@/composables/useManagerQueue'
109
import { useServerLogs } from '@/composables/useServerLogs'
1110
import { useComfyManagerService } from '@/services/comfyManagerService'
@@ -123,10 +122,6 @@ export const useComfyManagerStore = defineStore('comfyManager', () => {
123122
return key.split('@')[0]
124123
})
125124
installedPacks.value = packsWithCleanedKeys
126-
// Run conflict detection for all installed packages
127-
// This ensures conflict status is always up-to-date when installed list changes
128-
const { performConflictDetection } = useConflictDetection()
129-
await performConflictDetection()
130125
}
131126
isStale.value = false
132127
}

0 commit comments

Comments
 (0)