@@ -997,23 +997,30 @@ func makeSwitchCons(s *metal.Switch) []v1.SwitchConnection {
997997}
998998
999999func findSwitchReferencedEntities (s * metal.Switch , ds * datastore.RethinkStore ) (* metal.Partition , metal.IPsMap , metal.Machines , * metal.SwitchStatus , error ) {
1000- var err error
1001- var p * metal.Partition
1002- var m metal.Machines
1000+ var (
1001+ err error
1002+ p * metal.Partition
1003+ ms metal.Machines
1004+ projects []string
1005+ )
10031006
10041007 if s .PartitionID != "" {
10051008 p , err = ds .FindPartition (s .PartitionID )
10061009 if err != nil {
10071010 return nil , nil , nil , nil , fmt .Errorf ("switch %q references partition, but partition %q cannot be found in database: %w" , s .ID , s .PartitionID , err )
10081011 }
10091012
1010- err = ds .SearchMachines (& datastore.MachineSearchQuery {PartitionID : & s .PartitionID }, & m )
1013+ err = ds .SearchMachines (& datastore.MachineSearchQuery {PartitionID : & s .PartitionID }, & ms )
10111014 if err != nil {
10121015 return nil , nil , nil , nil , fmt .Errorf ("could not search machines of partition %q for switch %q: %w" , s .PartitionID , s .ID , err )
10131016 }
10141017 }
10151018
1016- ips , err := ds .ListIPs ()
1019+ for project := range ms .ByProjectID () {
1020+ projects = append (projects , project )
1021+ }
1022+
1023+ ips , err := ds .FindIPsByProjects (projects )
10171024 if err != nil {
10181025 return nil , nil , nil , nil , fmt .Errorf ("ips could not be listed: %w" , err )
10191026 }
@@ -1023,7 +1030,7 @@ func findSwitchReferencedEntities(s *metal.Switch, ds *datastore.RethinkStore) (
10231030 return nil , nil , nil , nil , fmt .Errorf ("switchStatus could not be listed: %w" , err )
10241031 }
10251032
1026- return p , ips .ByProjectID (), m , ss , nil
1033+ return p , ips .ByProjectID (), ms , ss , nil
10271034}
10281035
10291036func makeSwitchResponseList (ss metal.Switches , ds * datastore.RethinkStore ) ([]* v1.SwitchResponse , error ) {
0 commit comments