sort template workflows by required vram (#6285)

## Summary

Resolves https://github.com/Comfy-Org/ComfyUI_frontend/issues/6281 by
implementing the stubbed out vram sorting. Previously was waiting for it
to be added to the templates data and it now has
(https://github.com/Comfy-Org/workflow_templates/blob/main/templates/index.json)

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-6285-sort-template-workflows-by-required-vram-2976d73d36508164a8f9fab438f53b21)
by [Unito](https://www.unito.io)
This commit is contained in:
Christian Byrne
2025-10-25 15:52:24 -07:00
committed by GitHub
parent 23e0d26ff8
commit 2ea6c92030
3 changed files with 261 additions and 3 deletions

View File

@@ -128,6 +128,17 @@ export function useTemplateFiltering(
})
})
const getVramMetric = (template: TemplateInfo) => {
if (
typeof template.vram === 'number' &&
Number.isFinite(template.vram) &&
template.vram > 0
) {
return template.vram
}
return Number.POSITIVE_INFINITY
}
const sortedTemplates = computed(() => {
const templates = [...filteredByLicenses.value]
@@ -145,9 +156,21 @@ export function useTemplateFiltering(
return dateB.getTime() - dateA.getTime()
})
case 'vram-low-to-high':
// TODO: Implement VRAM sorting when VRAM data is available
// For now, keep original order
return templates
return templates.sort((a, b) => {
const vramA = getVramMetric(a)
const vramB = getVramMetric(b)
if (vramA === vramB) {
const nameA = a.title || a.name || ''
const nameB = b.title || b.name || ''
return nameA.localeCompare(nameB)
}
if (vramA === Number.POSITIVE_INFINITY) return 1
if (vramB === Number.POSITIVE_INFINITY) return -1
return vramA - vramB
})
case 'model-size-low-to-high':
return templates.sort((a: any, b: any) => {
const sizeA =