mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-04 14:01:30 +02:00
* 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>
31 lines
689 B
Go
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)
|
|
}
|