Cleaning the store from functions returning StoreResult (#11602)

* Cleaning the store from functions returning StoreResult

* Removing unnecesary StoreChannel type
Этот коммит содержится в:
Jesús Espino
2019-07-29 12:38:46 +02:00
коммит произвёл GitHub
родитель c362f0e802
Коммит e067272e16
9 изменённых файлов: 109 добавлений и 210 удалений

Просмотреть файл

@@ -56,8 +56,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
close(privateChan)
}()
var userChan store.StoreChannel
var userInactiveChan store.StoreChannel
var userChan chan store.StoreResult
var userInactiveChan chan store.StoreResult
if teamId == "" {
userInactiveChan = make(chan store.StoreResult, 1)
go func() {
@@ -74,7 +74,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
}()
}
var postChan store.StoreChannel
var postChan chan store.StoreResult
if !skipIntensiveQueries {
postChan = make(chan store.StoreResult, 1)
go func() {
@@ -257,8 +257,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
close(sessionChan)
}()
var fileChan store.StoreChannel
var hashtagChan store.StoreChannel
var fileChan chan store.StoreResult
var hashtagChan chan store.StoreResult
if !skipIntensiveQueries {
fileChan = make(chan store.StoreResult, 1)

Просмотреть файл

@@ -158,9 +158,9 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
post.SanitizeProps()
var pchan store.StoreChannel
var pchan chan store.StoreResult
if len(post.RootId) > 0 {
pchan = make(store.StoreChannel, 1)
pchan = make(chan store.StoreResult, 1)
go func() {
r, pErr := a.Srv.Store.Post().Get(post.RootId)
pchan <- store.StoreResult{Data: r, Err: pErr}

Просмотреть файл

@@ -588,7 +588,7 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
}
var channel *model.Channel
var cchan store.StoreChannel
var cchan chan store.StoreResult
if len(channelName) != 0 {
if channelName[0] == '@' {
@@ -602,14 +602,14 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
}
}
} else if channelName[0] == '#' {
cchan = make(store.StoreChannel, 1)
cchan = make(chan store.StoreResult, 1)
go func() {
chnn, chnnErr := a.Srv.Store.Channel().GetByName(hook.TeamId, channelName[1:], true)
cchan <- store.StoreResult{Data: chnn, Err: chnnErr}
close(cchan)
}()
} else {
cchan = make(store.StoreChannel, 1)
cchan = make(chan store.StoreResult, 1)
go func() {
chnn, chnnErr := a.Srv.Store.Channel().GetByName(hook.TeamId, channelName, true)
cchan <- store.StoreResult{Data: chnn, Err: chnnErr}

Просмотреть файл

@@ -58,17 +58,6 @@ func NewLayeredStore(db LayeredStoreDatabaseLayer, metrics einterfaces.MetricsIn
type QueryFunction func(LayeredStoreSupplier) *LayeredStoreSupplierResult
func (s *LayeredStore) RunQuery(queryFunction QueryFunction) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := queryFunction(s.LayerChainHead)
storeChannel <- result.StoreResult
}()
return storeChannel
}
func (s *LayeredStore) Team() TeamStore {
return s.DatabaseLayer.Team()
}

Просмотреть файл

@@ -471,13 +471,7 @@ func (s SqlChannelStore) Save(channel *model.Channel, maxChannelsPerTeam int64)
}
defer finalizeTransaction(transaction)
channelResult := s.saveChannelT(transaction, channel, maxChannelsPerTeam)
var newChannel *model.Channel
if channelResult.Data != nil {
newChannel = channelResult.Data.(*model.Channel)
}
appErr := channelResult.Err
newChannel, appErr := s.saveChannelT(transaction, channel, maxChannelsPerTeam)
if appErr != nil {
return newChannel, appErr
}
@@ -534,15 +528,7 @@ func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1
defer finalizeTransaction(transaction)
directchannel.TeamId = ""
// After updating saveChannelT() should be:
// newChannel, appErr := s.saveChannelT(transaction, directchannel, 0)
channelResult := s.saveChannelT(transaction, directchannel, 0)
var newChannel *model.Channel
if channelResult.Data != nil {
newChannel = channelResult.Data.(*model.Channel)
}
appErr := channelResult.Err
newChannel, appErr := s.saveChannelT(transaction, directchannel, 0)
if appErr != nil {
return newChannel, appErr
}
@@ -551,19 +537,19 @@ func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1
member1.ChannelId = newChannel.Id
member2.ChannelId = newChannel.Id
member1Result := s.saveMemberT(transaction, member1, newChannel)
member2Result := member1Result
_, member1SaveErr := s.saveMemberT(transaction, member1, newChannel)
member2SaveErr := member1SaveErr
if member1.UserId != member2.UserId {
member2Result = s.saveMemberT(transaction, member2, newChannel)
_, member2SaveErr = s.saveMemberT(transaction, member2, newChannel)
}
if member1Result.Err != nil || member2Result.Err != nil {
if member1SaveErr != nil || member2SaveErr != nil {
details := ""
if member1Result.Err != nil {
details += "Member1Err: " + member1Result.Err.Message
if member1SaveErr != nil {
details += "Member1Err: " + member1SaveErr.Message
}
if member2Result.Err != nil {
details += "Member2Err: " + member2Result.Err.Message
if member2SaveErr != nil {
details += "Member2Err: " + member2SaveErr.Message
}
return nil, model.NewAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.add_members.app_error", nil, details, http.StatusInternalServerError)
}
@@ -576,26 +562,21 @@ func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1
}
func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *model.Channel, maxChannelsPerTeam int64) store.StoreResult {
result := store.StoreResult{}
func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *model.Channel, maxChannelsPerTeam int64) (*model.Channel, *model.AppError) {
if len(channel.Id) > 0 {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.existing.app_error", nil, "id="+channel.Id, http.StatusBadRequest)
return result
return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.existing.app_error", nil, "id="+channel.Id, http.StatusBadRequest)
}
channel.PreSave()
if result.Err = channel.IsValid(); result.Err != nil {
return result
if err := channel.IsValid(); err != nil {
return nil, err
}
if channel.Type != model.CHANNEL_DIRECT && channel.Type != model.CHANNEL_GROUP && maxChannelsPerTeam >= 0 {
if count, err := transaction.SelectInt("SELECT COUNT(0) FROM Channels WHERE TeamId = :TeamId AND DeleteAt = 0 AND (Type = 'O' OR Type = 'P')", map[string]interface{}{"TeamId": channel.TeamId}); err != nil {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.current_count.app_error", nil, "teamId="+channel.TeamId+", "+err.Error(), http.StatusInternalServerError)
return result
return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.current_count.app_error", nil, "teamId="+channel.TeamId+", "+err.Error(), http.StatusInternalServerError)
} else if count >= maxChannelsPerTeam {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.limit.app_error", nil, "teamId="+channel.TeamId, http.StatusBadRequest)
return result
return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.limit.app_error", nil, "teamId="+channel.TeamId, http.StatusBadRequest)
}
}
@@ -604,19 +585,13 @@ func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *mo
dupChannel := model.Channel{}
s.GetMaster().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name})
if dupChannel.DeleteAt > 0 {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.previously.app_error", nil, "id="+channel.Id+", "+err.Error(), http.StatusBadRequest)
} else {
result.Err = model.NewAppError("SqlChannelStore.Save", store.CHANNEL_EXISTS_ERROR, nil, "id="+channel.Id+", "+err.Error(), http.StatusBadRequest)
result.Data = &dupChannel
return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.previously.app_error", nil, "id="+channel.Id+", "+err.Error(), http.StatusBadRequest)
}
} else {
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.save.app_error", nil, "id="+channel.Id+", "+err.Error(), http.StatusInternalServerError)
return &dupChannel, model.NewAppError("SqlChannelStore.Save", store.CHANNEL_EXISTS_ERROR, nil, "id="+channel.Id+", "+err.Error(), http.StatusBadRequest)
}
} else {
result.Data = channel
return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.save.app_error", nil, "id="+channel.Id+", "+err.Error(), http.StatusInternalServerError)
}
return result
return channel, nil
}
// Update writes the updated channel to the database.
@@ -790,9 +765,9 @@ func (s SqlChannelStore) SetDeleteAt(channelId string, deleteAt, updateAt int64)
}
defer finalizeTransaction(transaction)
var result = s.setDeleteAtT(transaction, channelId, deleteAt, updateAt)
if result.Err != nil {
return result.Err
appErr := s.setDeleteAtT(transaction, channelId, deleteAt, updateAt)
if appErr != nil {
return appErr
}
// Additionally propagate the write to the PublicChannels table.
@@ -817,16 +792,13 @@ func (s SqlChannelStore) SetDeleteAt(channelId string, deleteAt, updateAt int64)
return nil
}
func (s SqlChannelStore) setDeleteAtT(transaction *gorp.Transaction, channelId string, deleteAt, updateAt int64) store.StoreResult {
result := store.StoreResult{}
func (s SqlChannelStore) setDeleteAtT(transaction *gorp.Transaction, channelId string, deleteAt, updateAt int64) *model.AppError {
_, err := transaction.Exec("Update Channels SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :ChannelId", map[string]interface{}{"DeleteAt": deleteAt, "UpdateAt": updateAt, "ChannelId": channelId})
if err != nil {
result.Err = model.NewAppError("SqlChannelStore.Delete", "store.sql_channel.delete.channel.app_error", nil, "id="+channelId+", err="+err.Error(), http.StatusInternalServerError)
return result
return model.NewAppError("SqlChannelStore.Delete", "store.sql_channel.delete.channel.app_error", nil, "id="+channelId+", err="+err.Error(), http.StatusInternalServerError)
}
return result
return nil
}
// PermanentDeleteByTeam removes all channels for the given team from the database.
@@ -1311,49 +1283,42 @@ func (s SqlChannelStore) SaveMember(member *model.ChannelMember) (*model.Channel
}
defer finalizeTransaction(transaction)
storeResult := s.saveMemberT(transaction, member, channel)
if storeResult.Err != nil {
return nil, storeResult.Err
newMember, appErr := s.saveMemberT(transaction, member, channel)
if appErr != nil {
return nil, appErr
}
if err := transaction.Commit(); err != nil {
return nil, model.NewAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return storeResult.Data.(*model.ChannelMember), nil
return newMember, nil
}
func (s SqlChannelStore) saveMemberT(transaction *gorp.Transaction, member *model.ChannelMember, channel *model.Channel) store.StoreResult {
result := store.StoreResult{}
func (s SqlChannelStore) saveMemberT(transaction *gorp.Transaction, member *model.ChannelMember, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
member.PreSave()
if result.Err = member.IsValid(); result.Err != nil {
return result
if err := member.IsValid(); err != nil {
return nil, err
}
dbMember := NewChannelMemberFromModel(member)
if err := transaction.Insert(dbMember); err != nil {
if IsUniqueConstraintError(err, []string{"ChannelId", "channelmembers_pkey"}) {
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.exists.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error(), http.StatusBadRequest)
return result
return nil, model.NewAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.exists.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error(), http.StatusBadRequest)
}
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.save.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error(), http.StatusInternalServerError)
return result
return nil, model.NewAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.save.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error(), http.StatusInternalServerError)
}
var retrievedMember channelMemberWithSchemeRoles
if err := transaction.SelectOne(&retrievedMember, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": dbMember.ChannelId, "UserId": dbMember.UserId}); err != nil {
if err == sql.ErrNoRows {
result.Err = model.NewAppError("SqlChannelStore.GetMember", store.MISSING_CHANNEL_MEMBER_ERROR, nil, "channel_id="+dbMember.ChannelId+"user_id="+dbMember.UserId+","+err.Error(), http.StatusNotFound)
return result
return nil, model.NewAppError("SqlChannelStore.GetMember", store.MISSING_CHANNEL_MEMBER_ERROR, nil, "channel_id="+dbMember.ChannelId+"user_id="+dbMember.UserId+","+err.Error(), http.StatusNotFound)
}
result.Err = model.NewAppError("SqlChannelStore.GetMember", "store.sql_channel.get_member.app_error", nil, "channel_id="+dbMember.ChannelId+"user_id="+dbMember.UserId+","+err.Error(), http.StatusInternalServerError)
return result
return nil, model.NewAppError("SqlChannelStore.GetMember", "store.sql_channel.get_member.app_error", nil, "channel_id="+dbMember.ChannelId+"user_id="+dbMember.UserId+","+err.Error(), http.StatusInternalServerError)
}
result.Data = retrievedMember.ToModel()
return result
return retrievedMember.ToModel(), nil
}
func (s SqlChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) {

Просмотреть файл

@@ -464,8 +464,18 @@ func (s *SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFr
s.metrics.IncrementMemCacheMissCounter("Last Posts Cache")
}
rpc := s.getRootPosts(channelId, offset, limit)
cpc := s.getParentsPosts(channelId, offset, limit)
rpc := make(chan store.StoreResult, 1)
go func() {
posts, err := s.getRootPosts(channelId, offset, limit)
rpc <- store.StoreResult{Data: posts, Err: err}
close(rpc)
}()
cpc := make(chan store.StoreResult, 1)
go func() {
posts, err := s.getParentsPosts(channelId, offset, limit)
cpc <- store.StoreResult{Data: posts, Err: err}
close(cpc)
}()
var err *model.AppError
list := model.NewPostList()
@@ -735,52 +745,46 @@ func (s *SqlPostStore) GetPostAfterTime(channelId string, time int64) (*model.Po
return post, nil
}
func (s *SqlPostStore) getRootPosts(channelId string, offset int, limit int) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
var posts []*model.Post
_, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt DESC LIMIT :Limit OFFSET :Offset", map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit})
if err != nil {
result.Err = model.NewAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_root_posts.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError)
} else {
result.Data = posts
}
})
func (s *SqlPostStore) getRootPosts(channelId string, offset int, limit int) ([]*model.Post, *model.AppError) {
var posts []*model.Post
_, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt DESC LIMIT :Limit OFFSET :Offset", map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit})
if err != nil {
return nil, model.NewAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_root_posts.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError)
}
return posts, nil
}
func (s *SqlPostStore) getParentsPosts(channelId string, offset int, limit int) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
var posts []*model.Post
_, err := s.GetReplica().Select(&posts,
`SELECT
q2.*
func (s *SqlPostStore) getParentsPosts(channelId string, offset int, limit int) ([]*model.Post, *model.AppError) {
var posts []*model.Post
_, err := s.GetReplica().Select(&posts,
`SELECT
q2.*
FROM
Posts q2
INNER JOIN
(SELECT DISTINCT
q3.RootId
FROM
Posts q2
INNER JOIN
(SELECT DISTINCT
q3.RootId
FROM
(SELECT
RootId
FROM
Posts
WHERE
ChannelId = :ChannelId1
AND DeleteAt = 0
ORDER BY CreateAt DESC
LIMIT :Limit OFFSET :Offset) q3
WHERE q3.RootId != '') q1
ON q1.RootId = q2.Id OR q1.RootId = q2.RootId
WHERE
ChannelId = :ChannelId2
AND DeleteAt = 0
ORDER BY CreateAt`,
map[string]interface{}{"ChannelId1": channelId, "Offset": offset, "Limit": limit, "ChannelId2": channelId})
if err != nil {
result.Err = model.NewAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_parents_posts.app_error", nil, "channelId="+channelId+" err="+err.Error(), http.StatusInternalServerError)
} else {
result.Data = posts
}
})
(SELECT
RootId
FROM
Posts
WHERE
ChannelId = :ChannelId1
AND DeleteAt = 0
ORDER BY CreateAt DESC
LIMIT :Limit OFFSET :Offset) q3
WHERE q3.RootId != '') q1
ON q1.RootId = q2.Id OR q1.RootId = q2.RootId
WHERE
ChannelId = :ChannelId2
AND DeleteAt = 0
ORDER BY CreateAt`,
map[string]interface{}{"ChannelId1": channelId, "Offset": offset, "Limit": limit, "ChannelId2": channelId})
if err != nil {
return nil, model.NewAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_parents_posts.app_error", nil, "channelId="+channelId+" err="+err.Error(), http.StatusInternalServerError)
}
return posts, nil
}
var specialSearchChar = []string{

Просмотреть файл

@@ -1161,11 +1161,7 @@ func (us SqlUserStore) Search(teamId string, term string, options *model.UserSea
if teamId != "" {
query = query.Join("TeamMembers tm ON ( tm.UserId = u.Id AND tm.DeleteAt = 0 AND tm.TeamId = ? )", teamId)
}
result := us.performSearch(query, term, options)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.User), nil
return us.performSearch(query, term, options)
}
func (us SqlUserStore) SearchWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
@@ -1182,11 +1178,7 @@ func (us SqlUserStore) SearchWithoutTeam(term string, options *model.UserSearchO
OrderBy("u.Username ASC").
Limit(uint64(options.Limit))
result := us.performSearch(query, term, options)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.User), nil
return us.performSearch(query, term, options)
}
func (us SqlUserStore) SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
@@ -1200,11 +1192,7 @@ func (us SqlUserStore) SearchNotInTeam(notInTeamId string, term string, options
query = applyTeamGroupConstrainedFilter(query, notInTeamId)
}
result := us.performSearch(query, term, options)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.User), nil
return us.performSearch(query, term, options)
}
func (us SqlUserStore) SearchNotInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
@@ -1222,11 +1210,7 @@ func (us SqlUserStore) SearchNotInChannel(teamId string, channelId string, term
query = applyChannelGroupConstrainedFilter(query, channelId)
}
result := us.performSearch(query, term, options)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.User), nil
return us.performSearch(query, term, options)
}
func (us SqlUserStore) SearchInChannel(channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
@@ -1235,11 +1219,7 @@ func (us SqlUserStore) SearchInChannel(channelId string, term string, options *m
OrderBy("Username ASC").
Limit(uint64(options.Limit))
result := us.performSearch(query, term, options)
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.User), nil
return us.performSearch(query, term, options)
}
var escapeLikeSearchChar = []string{
@@ -1284,9 +1264,7 @@ func generateSearchQuery(query sq.SelectBuilder, terms []string, fields []string
return query
}
func (us SqlUserStore) performSearch(query sq.SelectBuilder, term string, options *model.UserSearchOptions) store.StoreResult {
result := store.StoreResult{}
func (us SqlUserStore) performSearch(query sq.SelectBuilder, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
// These chars must be removed from the like query.
for _, c := range ignoreLikeSearchChar {
term = strings.Replace(term, c, "", -1)
@@ -1328,23 +1306,19 @@ func (us SqlUserStore) performSearch(query sq.SelectBuilder, term string, option
queryString, args, err := query.ToSql()
if err != nil {
result.Err = model.NewAppError("SqlUserStore.Search", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
return result
return nil, model.NewAppError("SqlUserStore.Search", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
}
var users []*model.User
if _, err := us.GetReplica().Select(&users, queryString, args...); err != nil {
result.Err = model.NewAppError("SqlUserStore.Search", "store.sql_user.search.app_error", nil,
return nil, model.NewAppError("SqlUserStore.Search", "store.sql_user.search.app_error", nil,
fmt.Sprintf("term=%v, search_type=%v, %v", term, searchType, err.Error()), http.StatusInternalServerError)
} else {
for _, u := range users {
u.Sanitize(map[string]bool{})
}
result.Data = users
}
for _, u := range users {
u.Sanitize(map[string]bool{})
}
return result
return users, nil
}
func (us SqlUserStore) AnalyticsGetInactiveUsersCount() (int64, *model.AppError) {

Просмотреть файл

@@ -4,8 +4,6 @@
package store
import (
"time"
"github.com/mattermost/mattermost-server/model"
)
@@ -14,30 +12,6 @@ type StoreResult struct {
Err *model.AppError
}
type StoreChannel chan StoreResult
func Do(f func(result *StoreResult)) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
f(&result)
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func Must(sc StoreChannel) interface{} {
r := <-sc
if r.Err != nil {
time.Sleep(time.Second)
panic(r.Err)
}
return r.Data
}
type Store interface {
Team() TeamStore
Channel() ChannelStore

Просмотреть файл

@@ -10,13 +10,6 @@ import (
"github.com/mattermost/mattermost-server/store/storetest/mocks"
)
// NewStoreChannel returns a channel that will receive the given result.
func NewStoreChannel(result store.StoreResult) store.StoreChannel {
ch := make(store.StoreChannel, 1)
ch <- result
return ch
}
// Store can be used to provide mock stores for testing.
type Store struct {
TeamStore mocks.TeamStore