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

Function GetUsernameById

model/user.go:782–807  ·  view source on GitHub ↗

GetUsernameById gets username from Redis first, falls back to DB if needed

(id int, fromDB bool)

Source from the content-addressed store, hash-verified

780
781// GetUsernameById gets username from Redis first, falls back to DB if needed
782func GetUsernameById(id int, fromDB bool) (username string, err error) {
783 defer func() {
784 // Update Redis cache asynchronously on successful DB read
785 if shouldUpdateRedis(fromDB, err) {
786 gopool.Go(func() {
787 if err := updateUserNameCache(id, username); err != nil {
788 common.SysError("failed to update user name cache: " + err.Error())
789 }
790 })
791 }
792 }()
793 if !fromDB && common.RedisEnabled {
794 username, err := getUserNameCache(id)
795 if err == nil {
796 return username, nil
797 }
798 // Don't return error - fall through to DB
799 }
800 fromDB = true
801 err = DB.Model(&User{}).Where("id = ?", id).Select("username").Find(&username).Error
802 if err != nil {
803 return "", err
804 }
805
806 return username, nil
807}
808
809func IsLinuxDOIdAlreadyTaken(linuxDOId string) bool {
810 var user User

Callers 1

RecordLogFunction · 0.85

Calls 5

SysErrorFunction · 0.92
shouldUpdateRedisFunction · 0.85
updateUserNameCacheFunction · 0.85
getUserNameCacheFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected