MCPcopy Index your code
hub / github.com/bytebase/bytebase / GetInstance

Method GetInstance

backend/store/instance.go:57–81  ·  view source on GitHub ↗

GetInstance gets an instance by the resource_id.

(ctx context.Context, find *FindInstanceMessage)

Source from the content-addressed store, hash-verified

55
56// GetInstance gets an instance by the resource_id.
57func (s *Store) GetInstance(ctx context.Context, find *FindInstanceMessage) (*InstanceMessage, error) {
58 if find.ResourceID != nil {
59 if v, ok := s.instanceCache.Get(getInstanceCacheKey(*find.ResourceID)); ok && s.enableCache {
60 return v, nil
61 }
62 }
63
64 // We will always return the resource regardless of its deleted state.
65 find.ShowDeleted = true
66
67 instances, err := s.ListInstances(ctx, find)
68 if err != nil {
69 return nil, errors.Wrapf(err, "failed to list instances with find instance message %+v", find)
70 }
71 if len(instances) == 0 {
72 return nil, nil
73 }
74 if len(instances) > 1 {
75 return nil, errors.Errorf("find %d instances with find instance message %+v, expected 1", len(instances), find)
76 }
77
78 instance := instances[0]
79 s.instanceCache.Add(getInstanceCacheKey(instance.ResourceID), instance)
80 return instance, nil
81}
82
83// ListInstances lists all instance.
84func (s *Store) ListInstances(ctx context.Context, find *FindInstanceMessage) ([]*InstanceMessage, error) {

Callers 2

UpdateInstanceMethod · 0.95

Calls 4

ListInstancesMethod · 0.95
getInstanceCacheKeyFunction · 0.85
GetMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected