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

Method ModelConfigByID

coderd/x/chatd/configcache.go:218–241  ·  view source on GitHub ↗
(ctx context.Context, id uuid.UUID)

Source from the content-addressed store, hash-verified

216}
217
218func (c *chatConfigCache) ModelConfigByID(ctx context.Context, id uuid.UUID) (database.ChatModelConfig, error) {
219 if config, ok := c.cachedModelConfig(id); ok {
220 return config, nil
221 }
222
223 snap := c.modelConfigSnapshot()
224 config, err := singleflightDoChan(ctx, &c.modelConfigFetches, fmt.Sprintf("%d:%s", snap.epoch, id), func() (database.ChatModelConfig, error) {
225 if cached, ok := c.cachedModelConfig(id); ok {
226 return cached, nil
227 }
228
229 fetched, err := c.db.GetChatModelConfigByID(c.ctx, id)
230 if err != nil {
231 return database.ChatModelConfig{}, err
232 }
233 c.storeModelConfig(snap, fetched)
234 return cloneModelConfig(fetched), nil
235 })
236 if err != nil {
237 return database.ChatModelConfig{}, err
238 }
239
240 return config, nil
241}
242
243func (c *chatConfigCache) cachedModelConfig(id uuid.UUID) (database.ChatModelConfig, bool) {
244 c.mu.RLock()

Calls 6

cachedModelConfigMethod · 0.95
modelConfigSnapshotMethod · 0.95
storeModelConfigMethod · 0.95
singleflightDoChanFunction · 0.85
cloneModelConfigFunction · 0.85