mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-16784] Sync GetUserTeamIds (#11579)
* [MM-16784] Sync GetUserTeamIds
* fix format
* [MM-16784] put error in one line
* [MM-16784] Remove docstring as per CR request
* [MM-16784] Revert "Remove docstring as per CR request"
This reverts commit 8a64d3841b.
This commit is contained in:
committed by
Jesús Espino
parent
eb4c97c3e8
commit
797d1dc40f
@@ -999,46 +999,42 @@ func (s SqlTeamStore) GetAllForExportAfter(limit int, afterId string) ([]*model.
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) GetUserTeamIds(userId string, allowFromCache bool) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
if allowFromCache {
|
||||
if cacheItem, ok := allTeamIdsForUserCache.Get(userId); ok {
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheHitCounter("All Team Ids for User")
|
||||
}
|
||||
result.Data = cacheItem.([]string)
|
||||
return
|
||||
// GetUserTeamIds get the team ids to which the user belongs to
|
||||
func (s SqlTeamStore) GetUserTeamIds(userID string, allowFromCache bool) ([]string, *model.AppError) {
|
||||
if allowFromCache {
|
||||
if cacheItem, ok := allTeamIdsForUserCache.Get(userID); ok {
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheHitCounter("All Team Ids for User")
|
||||
}
|
||||
return cacheItem.([]string), nil
|
||||
}
|
||||
}
|
||||
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheMissCounter("All Team Ids for User")
|
||||
}
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheMissCounter("All Team Ids for User")
|
||||
}
|
||||
|
||||
var teamIds []string
|
||||
_, err := s.GetReplica().Select(&teamIds, `
|
||||
SELECT
|
||||
TeamId
|
||||
FROM
|
||||
TeamMembers
|
||||
INNER JOIN
|
||||
Teams ON TeamMembers.TeamId = Teams.Id
|
||||
WHERE
|
||||
TeamMembers.UserId = :UserId
|
||||
AND TeamMembers.DeleteAt = 0
|
||||
AND Teams.DeleteAt = 0`,
|
||||
map[string]interface{}{"UserId": userId})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlTeamStore.GetUserTeamIds", "store.sql_team.get_user_team_ids.app_error", nil, "userId="+userId+" "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
var teamIds []string
|
||||
_, err := s.GetReplica().Select(&teamIds,
|
||||
`SELECT
|
||||
TeamId
|
||||
FROM
|
||||
TeamMembers
|
||||
INNER JOIN
|
||||
Teams ON TeamMembers.TeamId = Teams.Id
|
||||
WHERE
|
||||
TeamMembers.UserId = :UserId
|
||||
AND TeamMembers.DeleteAt = 0
|
||||
AND Teams.DeleteAt = 0`,
|
||||
map[string]interface{}{"UserId": userID})
|
||||
if err != nil {
|
||||
return []string{}, model.NewAppError("SqlTeamStore.GetUserTeamIds", "store.sql_team.get_user_team_ids.app_error", nil, "userID="+userID+" "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = teamIds
|
||||
|
||||
if allowFromCache {
|
||||
allTeamIdsForUserCache.AddWithExpiresInSecs(userId, teamIds, ALL_TEAM_IDS_FOR_USER_CACHE_SEC)
|
||||
}
|
||||
})
|
||||
if allowFromCache {
|
||||
allTeamIdsForUserCache.AddWithExpiresInSecs(userID, teamIds, ALL_TEAM_IDS_FOR_USER_CACHE_SEC)
|
||||
}
|
||||
return teamIds, nil
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) GetTeamMembersForExport(userId string) ([]*model.TeamMemberForExport, *model.AppError) {
|
||||
|
||||
@@ -123,7 +123,7 @@ type TeamStore interface {
|
||||
GetAllForExportAfter(limit int, afterId string) ([]*model.TeamForExport, *model.AppError)
|
||||
GetTeamMembersForExport(userId string) ([]*model.TeamMemberForExport, *model.AppError)
|
||||
UserBelongsToTeams(userId string, teamIds []string) StoreChannel
|
||||
GetUserTeamIds(userId string, allowFromCache bool) StoreChannel
|
||||
GetUserTeamIds(userId string, allowFromCache bool) ([]string, *model.AppError)
|
||||
InvalidateAllTeamIdsForUser(userId string)
|
||||
ClearCaches()
|
||||
}
|
||||
|
||||
@@ -584,19 +584,28 @@ func (_m *TeamStore) GetTotalMemberCount(teamId string) (int64, *model.AppError)
|
||||
}
|
||||
|
||||
// GetUserTeamIds provides a mock function with given fields: userId, allowFromCache
|
||||
func (_m *TeamStore) GetUserTeamIds(userId string, allowFromCache bool) store.StoreChannel {
|
||||
func (_m *TeamStore) GetUserTeamIds(userId string, allowFromCache bool) ([]string, *model.AppError) {
|
||||
ret := _m.Called(userId, allowFromCache)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, bool) store.StoreChannel); ok {
|
||||
var r0 []string
|
||||
if rf, ok := ret.Get(0).(func(string, bool) []string); ok {
|
||||
r0 = rf(userId, allowFromCache)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).([]string)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, bool) *model.AppError); ok {
|
||||
r1 = rf(userId, allowFromCache)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// InvalidateAllTeamIdsForUser provides a mock function with given fields: userId
|
||||
|
||||
Reference in New Issue
Block a user