Avoid duplicate queries in auth (#827)
Avoid identical making calls to GetUserByID(..) in SignedInUser(..)
This commit is contained in:
parent
bf647ce143
commit
e86d935175
|
@ -69,14 +69,7 @@ func SignedInID(ctx *macaron.Context, sess session.Store) int64 {
|
||||||
uid := sess.Get("uid")
|
uid := sess.Get("uid")
|
||||||
if uid == nil {
|
if uid == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
} else if id, ok := uid.(int64); ok {
|
||||||
if id, ok := uid.(int64); ok {
|
|
||||||
if _, err := models.GetUserByID(id); err != nil {
|
|
||||||
if !models.IsErrUserNotExist(err) {
|
|
||||||
log.Error(4, "GetUserById: %v", err)
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
@ -89,9 +82,15 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (*models.User, bool)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
uid := SignedInID(ctx, sess)
|
if uid := SignedInID(ctx, sess); uid > 0 {
|
||||||
|
user, err := models.GetUserByID(uid)
|
||||||
|
if err == nil {
|
||||||
|
return user, false
|
||||||
|
} else if !models.IsErrUserNotExist(err) {
|
||||||
|
log.Error(4, "GetUserById: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if uid <= 0 {
|
|
||||||
if setting.Service.EnableReverseProxyAuth {
|
if setting.Service.EnableReverseProxyAuth {
|
||||||
webAuthUser := ctx.Req.Header.Get(setting.ReverseProxyAuthUser)
|
webAuthUser := ctx.Req.Header.Get(setting.ReverseProxyAuthUser)
|
||||||
if len(webAuthUser) > 0 {
|
if len(webAuthUser) > 0 {
|
||||||
|
@ -141,14 +140,6 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (*models.User, bool)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
|
||||||
|
|
||||||
u, err := models.GetUserByID(uid)
|
|
||||||
if err != nil {
|
|
||||||
log.Error(4, "GetUserById: %v", err)
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
return u, false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Form form binding interface
|
// Form form binding interface
|
||||||
|
|
Loading…
Reference in a new issue