Files
orchard/internal/controller/store/badger/badger_vm.go
T
Fedor KorotkovandCodex be869f10d4 Refactor listing VMs (#399)
* Removed unnesesary ListOptions

* Refactor genericList to accept string prefixes instead of byte slices

* Optimize VM listing logic with singleflight to deduplicate concurrent request

* Refactor VM listing logic: rename variables for clarity and update error messages

* fix: address PR review feedback

- use singleflight DoChan with context cancellation for list VMs

🤖 Generated with [Codex](https://chatgpt.com/codex)

Co-Authored-By: Codex <codex@openai.com>

---------

Co-authored-by: Codex <codex@openai.com>
2026-02-05 18:51:45 +01:00

31 lines
689 B
Go

//nolint:dupl // maybe we'll figure out how to make DB resource accessors generic in the future
package badger
import (
"path"
"github.com/cirruslabs/orchard/pkg/resource/v1"
)
const SpaceVMs = "/vms"
func VMKey(name string) []byte {
return []byte(path.Join(SpaceVMs, name))
}
func (txn *Transaction) GetVM(name string) (*v1.VM, error) {
return genericGet[v1.VM](txn, VMKey(name))
}
func (txn *Transaction) SetVM(vm v1.VM) error {
return genericSet[v1.VM](txn, VMKey(vm.Name), vm)
}
func (txn *Transaction) DeleteVM(name string) error {
return genericDelete(txn, VMKey(name))
}
func (txn *Transaction) ListVMs() ([]v1.VM, error) {
return genericList[v1.VM](txn, SpaceVMs)
}