mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 07:35:45 -06:00
fix failing tests
This commit is contained in:
parent
940f510856
commit
6ef941ea17
@ -326,6 +326,7 @@ func InitTestDB(t *testing.T) *SqlStore {
|
||||
sqlstore := &SqlStore{}
|
||||
sqlstore.skipEnsureAdmin = true
|
||||
sqlstore.Bus = bus.New()
|
||||
sqlstore.CacheService = cache.New(5*time.Minute, 10*time.Minute)
|
||||
|
||||
dbType := migrator.SQLITE
|
||||
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func (ss *SqlStore) addUserQueryAndCommandHandlers() {
|
||||
ss.Bus.AddHandler(ss.GetSignedInUser)
|
||||
ss.Bus.AddHandler(ss.GetSignedInUserWithCache)
|
||||
|
||||
bus.AddHandler("sql", GetUserById)
|
||||
bus.AddHandler("sql", UpdateUser)
|
||||
@ -345,18 +345,24 @@ func GetUserOrgList(query *m.GetUserOrgListQuery) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetSignedInUser(query *m.GetSignedInUserQuery) error {
|
||||
orgId := "u.org_id"
|
||||
if query.OrgId > 0 {
|
||||
orgId = strconv.FormatInt(query.OrgId, 10)
|
||||
}
|
||||
|
||||
cacheKey := fmt.Sprintf("signed-in-user-%d-%s", query.UserId, query.OrgId)
|
||||
func (ss *SqlStore) GetSignedInUserWithCache(query *m.GetSignedInUserQuery) error {
|
||||
cacheKey := fmt.Sprintf("signed-in-user-%d-%d", query.UserId, query.OrgId)
|
||||
if cached, found := ss.CacheService.Get(cacheKey); found {
|
||||
query.Result = cached.(*m.SignedInUser)
|
||||
return nil
|
||||
}
|
||||
|
||||
err := GetSignedInUser(query)
|
||||
ss.CacheService.Set(cacheKey, query.Result, time.Second*5)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetSignedInUser(query *m.GetSignedInUserQuery) error {
|
||||
orgId := "u.org_id"
|
||||
if query.OrgId > 0 {
|
||||
orgId = strconv.FormatInt(query.OrgId, 10)
|
||||
}
|
||||
|
||||
var rawSql = `SELECT
|
||||
u.id as user_id,
|
||||
u.is_admin as is_grafana_admin,
|
||||
@ -407,7 +413,6 @@ func (ss *SqlStore) GetSignedInUser(query *m.GetSignedInUserQuery) error {
|
||||
}
|
||||
|
||||
query.Result = &user
|
||||
ss.CacheService.Set(cacheKey, &user, time.Second*5)
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user