From 25706fb75c9aa807206330cba166dc0f7d9b3cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Thu, 30 Jul 2026 13:40:38 -0400 Subject: [PATCH] incusd/db/cluster: Add referenced profile query helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber Sponsored-by: https://webdock.io --- internal/server/db/cluster/profiles.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/server/db/cluster/profiles.go b/internal/server/db/cluster/profiles.go index 2a9fbe3462..91325c221c 100644 --- a/internal/server/db/cluster/profiles.go +++ b/internal/server/db/cluster/profiles.go @@ -172,3 +172,23 @@ func GetAllProfileConfigs(ctx context.Context, tx *sql.Tx) (map[int]map[string]s func GetAllProfileDevices(ctx context.Context, tx *sql.Tx) (map[int][]Device, error) { return GetDevices(ctx, tx, "profiles", "profile") } + +// GetReferencedProfileConfigs returns a map of the given profiles' configurations, keyed by database ID. +func GetReferencedProfileConfigs(ctx context.Context, tx *sql.Tx, profiles []Profile) (map[int]map[string]string, error) { + profileIDs := make([]int, 0, len(profiles)) + for _, profile := range profiles { + profileIDs = append(profileIDs, profile.ID) + } + + return GetConfig(ctx, tx, "profiles", "profile", ConfigFilter{ReferenceID: profileIDs}) +} + +// GetReferencedProfileDevices returns a map of the given profiles' devices, keyed by database ID. +func GetReferencedProfileDevices(ctx context.Context, tx *sql.Tx, profiles []Profile) (map[int][]Device, error) { + profileIDs := make([]int, 0, len(profiles)) + for _, profile := range profiles { + profileIDs = append(profileIDs, profile.ID) + } + + return GetDevices(ctx, tx, "profiles", "profile", DeviceFilter{ReferenceID: profileIDs}) +}