MCPcopy Create free account
hub / github.com/PatchMon/PatchMon / GetByIDs

Method GetByIDs

server-source-code/internal/store/hosts.go:95–115  ·  view source on GitHub ↗

GetByIDs returns hosts by IDs in one query. Preserves input order.

(ctx context.Context, ids []string)

Source from the content-addressed store, hash-verified

93
94// GetByIDs returns hosts by IDs in one query. Preserves input order.
95func (s *HostsStore) GetByIDs(ctx context.Context, ids []string) ([]models.Host, error) {
96 d := s.db.DB(ctx)
97 if len(ids) == 0 {
98 return nil, nil
99 }
100 rows, err := d.Queries.GetHostsByIDs(ctx, ids)
101 if err != nil {
102 return nil, err
103 }
104 byID := make(map[string]models.Host)
105 for _, h := range rows {
106 byID[h.ID] = *dbHostToModel(h)
107 }
108 ordered := make([]models.Host, 0, len(ids))
109 for _, id := range ids {
110 if h, ok := byID[id]; ok {
111 ordered = append(ordered, h)
112 }
113 }
114 return ordered, nil
115}
116
117// GetByApiID returns a host by api_id.
118func (s *HostsStore) GetByApiID(ctx context.Context, apiID string) (*models.Host, error) {

Callers 5

GetByIDMethod · 0.95
ListForScopedApiMethod · 0.95
BulkUpdateGroupsMethod · 0.80
TriggerBulkScanMethod · 0.80
GetHostsMethod · 0.80

Calls 3

dbHostToModelFunction · 0.85
DBMethod · 0.65
GetHostsByIDsMethod · 0.65

Tested by

no test coverage detected