|
|
@@ -37,8 +37,8 @@ type User struct {
|
|
|
Province string `orm:"column(province);null" json:"-"` // varchar(20)
|
|
|
City string `orm:"column(city);null" json:"-"` // varchar(20)
|
|
|
Sex int64 `orm:"column(sex);null" json:"sex"` // int(11)
|
|
|
- Race string `orm:"column(race);null" json:"race"`
|
|
|
- Occupation string `orm:"column(occupation);null" json:"occupation"`
|
|
|
+ Race string `orm:"-" json:"race"`
|
|
|
+ Occupation string `orm:"-" json:"occupation"`
|
|
|
Head string `orm:"column(head)" json:"head"`
|
|
|
Birthday time.Time `orm:"column(birthday);null;type(datetime)" json:"birthday"`
|
|
|
InviteId int64 `orm:"column(invite_id);null" json:"invite_id"` // int(11)
|
|
|
@@ -149,8 +149,16 @@ func GetUserById(id int64, useCache bool) *User {
|
|
|
o := orm.NewOrm()
|
|
|
err := o.QueryTable(usr).Filter("id", id).Limit(1).One(usr)
|
|
|
if err != nil {
|
|
|
- beego.Debug("GetByUid is not found err=[%s], id=%d", err, id)
|
|
|
- return nil
|
|
|
+ // Fall back to raw SQL when ORM metadata/query building drifts from the runtime schema.
|
|
|
+ rawUser := new(User)
|
|
|
+ rawErr := o.Raw("SELECT * FROM users WHERE id = ? LIMIT 1", id).QueryRow(rawUser)
|
|
|
+ if rawErr != nil {
|
|
|
+ beego.BeeLogger.Error("GetByUid failed, id=%d, query_err=[%s], raw_err=[%s]", id, err, rawErr)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ cache.Cache.Put(k, rawUser, 5*time.Minute)
|
|
|
+ beego.BeeLogger.Warn("GetByUid recovered via raw SQL, id=%d, query_err=[%s]", id, err)
|
|
|
+ return rawUser
|
|
|
} else {
|
|
|
cache.Cache.Put(k, usr, 5*time.Minute)
|
|
|
return usr
|