feat(lora-cycler): implement batch queue synchronization with dual-index mechanism

- Add execution_index and next_index fields to CyclerConfig interface
- Introduce beforeQueued hook in widget to handle index shifting for batch executions
- Use execution_index when provided, fall back to current_index for single executions
- Track execution state with Symbol to differentiate first vs subsequent executions
- Update state management to handle dual-index logic for proper LoRA cycling in batch queues
This commit is contained in:
Will Miao
2026-01-22 21:22:52 +08:00
parent bf0291ec0e
commit 2121054cb9
6 changed files with 126 additions and 6 deletions

View File

@@ -34,6 +34,9 @@ const props = defineProps<{
// State management
const state = useLoraCyclerState(props.widget)
// Symbol to track if the widget has been executed at least once
const HAS_EXECUTED = Symbol('HAS_EXECUTED')
// Track last known pool config hash
const lastPoolConfigHash = ref('')
@@ -124,6 +127,28 @@ onMounted(async () => {
state.restoreFromConfig(props.widget.value as CyclerConfig)
}
// Add beforeQueued hook to handle index shifting for batch queue synchronization
// This ensures each execution uses a different LoRA in the cycle
;(props.widget as any).beforeQueued = () => {
if ((props.widget as any)[HAS_EXECUTED]) {
// After first execution: shift indices (previous next_index becomes execution_index)
state.generateNextIndex()
} else {
// First execution: just initialize next_index (execution_index stays null)
// This means first execution uses current_index from widget
state.initializeNextIndex()
;(props.widget as any)[HAS_EXECUTED] = true
}
// Update the widget value so the indices are included in the serialized config
const config = state.buildConfig()
if ((props.widget as any).updateConfig) {
;(props.widget as any).updateConfig(config)
} else {
props.widget.value = config
}
}
// Mark component as mounted
isMounted.value = true