MCPcopy Index your code
hub / github.com/coder/coder / EnabledProviders

Method EnabledProviders

coderd/x/chatd/configcache.go:134–162  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

132}
133
134func (c *chatConfigCache) EnabledProviders(ctx context.Context) ([]database.AIProvider, error) {
135 if providers, ok := c.cachedProviders(); ok {
136 return providers, nil
137 }
138
139 generation := c.providersGeneration()
140 providers, err := singleflightDoChan(
141 ctx,
142 &c.providerFetches,
143 fmt.Sprintf("%d:providers", generation),
144 func() ([]database.AIProvider, error) {
145 if cached, ok := c.cachedProviders(); ok {
146 return cached, nil
147 }
148
149 fetched, err := c.db.GetAIProviders(c.ctx, database.GetAIProvidersParams{})
150 if err != nil {
151 return nil, err
152 }
153 c.storeProviders(generation, fetched)
154 return slices.Clone(fetched), nil
155 },
156 )
157 if err != nil {
158 return nil, err
159 }
160
161 return slices.Clone(providers), nil
162}
163
164func (c *chatConfigCache) cachedProviders() ([]database.AIProvider, bool) {
165 c.mu.RLock()

Calls 6

cachedProvidersMethod · 0.95
providersGenerationMethod · 0.95
storeProvidersMethod · 0.95
singleflightDoChanFunction · 0.85
GetAIProvidersMethod · 0.65
CloneMethod · 0.45