MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / GetTokenByKey

Function GetTokenByKey

model/token.go:168–190  ·  view source on GitHub ↗
(key string, fromDB bool)

Source from the content-addressed store, hash-verified

166}
167
168func GetTokenByKey(key string, fromDB bool) (token *Token, err error) {
169 defer func() {
170 // Update Redis cache asynchronously on successful DB read
171 if shouldUpdateRedis(fromDB, err) && token != nil {
172 gopool.Go(func() {
173 if err := cacheSetToken(*token); err != nil {
174 common.SysError("failed to update user status cache: " + err.Error())
175 }
176 })
177 }
178 }()
179 if !fromDB && common.RedisEnabled {
180 // Try Redis first
181 token, err := cacheGetTokenByKey(key)
182 if err == nil {
183 return token, nil
184 }
185 // Don't return error - fall through to DB
186 }
187 fromDB = true
188 err = DB.Where(commonKeyCol+" = ?", key).First(&token).Error
189 return token, err
190}
191
192func (token *Token) Insert() error {
193 var err error

Callers 5

SearchTokenByTokenFunction · 0.92
PreWssConsumeQuotaFunction · 0.92
PreConsumeTokenQuotaFunction · 0.92
ValidateUserTokenFunction · 0.85
IncreaseTokenUsageCountFunction · 0.85

Calls 5

SysErrorFunction · 0.92
shouldUpdateRedisFunction · 0.85
cacheSetTokenFunction · 0.85
cacheGetTokenByKeyFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected