Skip to content

Commit

Permalink
[MM-56284] Remove non-generic StoreResult (mattermost#25750)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Jan 4, 2024
1 parent 502cd6e commit edc3057
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 123 deletions.
28 changes: 14 additions & 14 deletions server/channels/app/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -1401,18 +1401,18 @@ func (a *App) updateChannelMember(c request.CTX, member *model.ChannelMember) (*
}

func (a *App) DeleteChannel(c request.CTX, channel *model.Channel, userID string) *model.AppError {
ihc := make(chan store.GenericStoreResult[[]*model.IncomingWebhook], 1)
ohc := make(chan store.GenericStoreResult[[]*model.OutgoingWebhook], 1)
ihc := make(chan store.StoreResult[[]*model.IncomingWebhook], 1)
ohc := make(chan store.StoreResult[[]*model.OutgoingWebhook], 1)

go func() {
webhooks, err := a.Srv().Store().Webhook().GetIncomingByChannel(channel.Id)
ihc <- store.GenericStoreResult[[]*model.IncomingWebhook]{Data: webhooks, NErr: err}
ihc <- store.StoreResult[[]*model.IncomingWebhook]{Data: webhooks, NErr: err}
close(ihc)
}()

go func() {
outgoingHooks, err := a.Srv().Store().Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
ohc <- store.GenericStoreResult[[]*model.OutgoingWebhook]{Data: outgoingHooks, NErr: err}
ohc <- store.StoreResult[[]*model.OutgoingWebhook]{Data: outgoingHooks, NErr: err}
close(ohc)
}()

Expand Down Expand Up @@ -2210,16 +2210,16 @@ func (a *App) GetChannelUnread(c request.CTX, channelID, userID string) (*model.
}

func (a *App) JoinChannel(c request.CTX, channel *model.Channel, userID string) *model.AppError {
userChan := make(chan store.GenericStoreResult[*model.User], 1)
memberChan := make(chan store.GenericStoreResult[*model.ChannelMember], 1)
userChan := make(chan store.StoreResult[*model.User], 1)
memberChan := make(chan store.StoreResult[*model.ChannelMember], 1)
go func() {
user, err := a.Srv().Store().User().Get(context.Background(), userID)
userChan <- store.GenericStoreResult[*model.User]{Data: user, NErr: err}
userChan <- store.StoreResult[*model.User]{Data: user, NErr: err}
close(userChan)
}()
go func() {
member, err := a.Srv().Store().Channel().GetMember(context.Background(), channel.Id, userID)
memberChan <- store.GenericStoreResult[*model.ChannelMember]{Data: member, NErr: err}
memberChan <- store.StoreResult[*model.ChannelMember]{Data: member, NErr: err}
close(memberChan)
}()

Expand Down Expand Up @@ -2311,24 +2311,24 @@ func (a *App) postJoinTeamMessage(c request.CTX, user *model.User, channel *mode
}

func (a *App) LeaveChannel(c request.CTX, channelID string, userID string) *model.AppError {
sc := make(chan store.GenericStoreResult[*model.Channel], 1)
sc := make(chan store.StoreResult[*model.Channel], 1)
go func() {
channel, err := a.Srv().Store().Channel().Get(channelID, true)
sc <- store.GenericStoreResult[*model.Channel]{Data: channel, NErr: err}
sc <- store.StoreResult[*model.Channel]{Data: channel, NErr: err}
close(sc)
}()

uc := make(chan store.GenericStoreResult[*model.User], 1)
uc := make(chan store.StoreResult[*model.User], 1)
go func() {
user, err := a.Srv().Store().User().Get(context.Background(), userID)
uc <- store.GenericStoreResult[*model.User]{Data: user, NErr: err}
uc <- store.StoreResult[*model.User]{Data: user, NErr: err}
close(uc)
}()

mcc := make(chan store.GenericStoreResult[int64], 1)
mcc := make(chan store.StoreResult[int64], 1)
go func() {
count, err := a.Srv().Store().Channel().GetMemberCount(channelID, false)
mcc <- store.GenericStoreResult[int64]{Data: count, NErr: err}
mcc <- store.StoreResult[int64]{Data: count, NErr: err}
close(mcc)
}()

Expand Down
12 changes: 6 additions & 6 deletions server/channels/app/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,24 +369,24 @@ func (a *App) tryExecuteCustomCommand(c request.CTX, args *model.CommandArgs, tr
return nil, nil, model.NewAppError("ExecuteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
}

chanChan := make(chan store.GenericStoreResult[*model.Channel], 1)
chanChan := make(chan store.StoreResult[*model.Channel], 1)
go func() {
channel, err := a.Srv().Store().Channel().Get(args.ChannelId, true)
chanChan <- store.GenericStoreResult[*model.Channel]{Data: channel, NErr: err}
chanChan <- store.StoreResult[*model.Channel]{Data: channel, NErr: err}
close(chanChan)
}()

teamChan := make(chan store.GenericStoreResult[*model.Team], 1)
teamChan := make(chan store.StoreResult[*model.Team], 1)
go func() {
team, err := a.Srv().Store().Team().Get(args.TeamId)
teamChan <- store.GenericStoreResult[*model.Team]{Data: team, NErr: err}
teamChan <- store.StoreResult[*model.Team]{Data: team, NErr: err}
close(teamChan)
}()

userChan := make(chan store.GenericStoreResult[*model.User], 1)
userChan := make(chan store.StoreResult[*model.User], 1)
go func() {
user, err := a.Srv().Store().User().Get(context.Background(), args.UserId)
userChan <- store.GenericStoreResult[*model.User]{Data: user, NErr: err}
userChan <- store.StoreResult[*model.User]{Data: user, NErr: err}
close(userChan)
}()

Expand Down
16 changes: 8 additions & 8 deletions server/channels/app/integration_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,24 @@ func (a *App) DoPostActionWithCookie(c request.CTX, postID, actionId, userID, se

// See if the post exists in the DB, if so ignore the cookie.
// Start all queries here for parallel execution
pchan := make(chan store.GenericStoreResult[*model.Post], 1)
pchan := make(chan store.StoreResult[*model.Post], 1)
go func() {
post, err := a.Srv().Store().Post().GetSingle(postID, false)
pchan <- store.GenericStoreResult[*model.Post]{Data: post, NErr: err}
pchan <- store.StoreResult[*model.Post]{Data: post, NErr: err}
close(pchan)
}()

cchan := make(chan store.GenericStoreResult[*model.Channel], 1)
cchan := make(chan store.StoreResult[*model.Channel], 1)
go func() {
channel, err := a.Srv().Store().Channel().GetForPost(postID)
cchan <- store.GenericStoreResult[*model.Channel]{Data: channel, NErr: err}
cchan <- store.StoreResult[*model.Channel]{Data: channel, NErr: err}
close(cchan)
}()

userChan := make(chan store.GenericStoreResult[*model.User], 1)
userChan := make(chan store.StoreResult[*model.User], 1)
go func() {
user, err := a.Srv().Store().User().Get(context.Background(), upstreamRequest.UserId)
userChan <- store.GenericStoreResult[*model.User]{Data: user, NErr: err}
userChan <- store.StoreResult[*model.User]{Data: user, NErr: err}
close(userChan)
}()

Expand Down Expand Up @@ -172,7 +172,7 @@ func (a *App) DoPostActionWithCookie(c request.CTX, postID, actionId, userID, se
upstreamURL = action.Integration.URL
}

teamChan := make(chan store.GenericStoreResult[*model.Team], 1)
teamChan := make(chan store.StoreResult[*model.Team], 1)

go func() {
defer close(teamChan)
Expand All @@ -183,7 +183,7 @@ func (a *App) DoPostActionWithCookie(c request.CTX, postID, actionId, userID, se
}

team, err := a.Srv().Store().Team().Get(upstreamRequest.TeamId)
teamChan <- store.GenericStoreResult[*model.Team]{Data: team, NErr: err}
teamChan <- store.StoreResult[*model.Team]{Data: team, NErr: err}
}()

ur := <-userChan
Expand Down
40 changes: 20 additions & 20 deletions server/channels/app/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,46 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea

isCRTAllowed := *a.Config().ServiceSettings.CollapsedThreads != model.CollapsedThreadsDisabled

pchan := make(chan store.GenericStoreResult[map[string]*model.User], 1)
pchan := make(chan store.StoreResult[map[string]*model.User], 1)
go func() {
props, err := a.Srv().Store().User().GetAllProfilesInChannel(context.Background(), channel.Id, true)
pchan <- store.GenericStoreResult[map[string]*model.User]{Data: props, NErr: err}
pchan <- store.StoreResult[map[string]*model.User]{Data: props, NErr: err}
close(pchan)
}()

cmnchan := make(chan store.GenericStoreResult[map[string]model.StringMap], 1)
cmnchan := make(chan store.StoreResult[map[string]model.StringMap], 1)
go func() {
props, err := a.Srv().Store().Channel().GetAllChannelMembersNotifyPropsForChannel(channel.Id, true)
cmnchan <- store.GenericStoreResult[map[string]model.StringMap]{Data: props, NErr: err}
cmnchan <- store.StoreResult[map[string]model.StringMap]{Data: props, NErr: err}
close(cmnchan)
}()

var gchan chan store.GenericStoreResult[map[string]*model.Group]
var gchan chan store.StoreResult[map[string]*model.Group]
if a.allowGroupMentions(c, post) {
gchan = make(chan store.GenericStoreResult[map[string]*model.Group], 1)
gchan = make(chan store.StoreResult[map[string]*model.Group], 1)
go func() {
groupsMap, err := a.getGroupsAllowedForReferenceInChannel(channel, team)
gchan <- store.GenericStoreResult[map[string]*model.Group]{Data: groupsMap, NErr: err}
gchan <- store.StoreResult[map[string]*model.Group]{Data: groupsMap, NErr: err}
close(gchan)
}()
}

var fchan chan store.GenericStoreResult[[]*model.FileInfo]
var fchan chan store.StoreResult[[]*model.FileInfo]
if len(post.FileIds) != 0 {
fchan = make(chan store.GenericStoreResult[[]*model.FileInfo], 1)
fchan = make(chan store.StoreResult[[]*model.FileInfo], 1)
go func() {
fileInfos, err := a.Srv().Store().FileInfo().GetForPost(post.Id, true, false, true)
fchan <- store.GenericStoreResult[[]*model.FileInfo]{Data: fileInfos, NErr: err}
fchan <- store.StoreResult[[]*model.FileInfo]{Data: fileInfos, NErr: err}
close(fchan)
}()
}

var tchan chan store.GenericStoreResult[[]string]
var tchan chan store.StoreResult[[]string]
if isCRTAllowed && post.RootId != "" {
tchan = make(chan store.GenericStoreResult[[]string], 1)
tchan = make(chan store.StoreResult[[]string], 1)
go func() {
followers, err := a.Srv().Store().Thread().GetThreadFollowers(post.RootId, true)
tchan <- store.GenericStoreResult[[]string]{Data: followers, NErr: err}
tchan <- store.StoreResult[[]string]{Data: followers, NErr: err}
close(tchan)
}()
}
Expand Down Expand Up @@ -627,26 +627,26 @@ func (a *App) RemoveNotifications(c request.CTX, post *model.Post, channel *mode
team = &model.Team{}
}

pCh := make(chan store.GenericStoreResult[map[string]*model.User], 1)
pCh := make(chan store.StoreResult[map[string]*model.User], 1)
go func() {
props, err := a.Srv().Store().User().GetAllProfilesInChannel(context.Background(), channel.Id, true)
pCh <- store.GenericStoreResult[map[string]*model.User]{Data: props, NErr: err}
pCh <- store.StoreResult[map[string]*model.User]{Data: props, NErr: err}
close(pCh)
}()

cmnCh := make(chan store.GenericStoreResult[map[string]model.StringMap], 1)
cmnCh := make(chan store.StoreResult[map[string]model.StringMap], 1)
go func() {
props, err := a.Srv().Store().Channel().GetAllChannelMembersNotifyPropsForChannel(channel.Id, true)
cmnCh <- store.GenericStoreResult[map[string]model.StringMap]{Data: props, NErr: err}
cmnCh <- store.StoreResult[map[string]model.StringMap]{Data: props, NErr: err}
close(cmnCh)
}()

var gCh chan store.GenericStoreResult[map[string]*model.Group]
var gCh chan store.StoreResult[map[string]*model.Group]
if a.allowGroupMentions(c, post) {
gCh = make(chan store.GenericStoreResult[map[string]*model.Group], 1)
gCh = make(chan store.StoreResult[map[string]*model.Group], 1)
go func() {
groupsMap, err := a.getGroupsAllowedForReferenceInChannel(channel, team)
gCh <- store.GenericStoreResult[map[string]*model.Group]{Data: groupsMap, NErr: err}
gCh <- store.StoreResult[map[string]*model.Group]{Data: groupsMap, NErr: err}
close(gCh)
}()
}
Expand Down
14 changes: 7 additions & 7 deletions server/channels/app/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel

post.SanitizeProps()

var pchan chan store.GenericStoreResult[*model.PostList]
var pchan chan store.StoreResult[*model.PostList]
if post.RootId != "" {
pchan = make(chan store.GenericStoreResult[*model.PostList], 1)
pchan = make(chan store.StoreResult[*model.PostList], 1)
go func() {
r, pErr := a.Srv().Store().Post().Get(sqlstore.WithMaster(context.Background()), post.RootId, model.GetPostsOptions{}, "", a.Config().GetSanitizeOptions())
pchan <- store.GenericStoreResult[*model.PostList]{Data: r, NErr: pErr}
pchan <- store.StoreResult[*model.PostList]{Data: r, NErr: pErr}
close(pchan)
}()
}
Expand Down Expand Up @@ -1474,7 +1474,7 @@ func (a *App) parseAndFetchChannelIdByNameFromInFilter(c request.CTX, channelNam
func (a *App) searchPostsInTeam(teamID string, userID string, paramsList []*model.SearchParams, modifierFun func(*model.SearchParams)) (*model.PostList, *model.AppError) {
var wg sync.WaitGroup

pchan := make(chan store.GenericStoreResult[*model.PostList], len(paramsList))
pchan := make(chan store.StoreResult[*model.PostList], len(paramsList))

for _, params := range paramsList {
// Don't allow users to search for everything.
Expand All @@ -1487,7 +1487,7 @@ func (a *App) searchPostsInTeam(teamID string, userID string, paramsList []*mode
go func(params *model.SearchParams) {
defer wg.Done()
postList, err := a.Srv().Store().Post().Search(teamID, userID, params)
pchan <- store.GenericStoreResult[*model.PostList]{Data: postList, NErr: err}
pchan <- store.StoreResult[*model.PostList]{Data: postList, NErr: err}
}(params)
}

Expand Down Expand Up @@ -1696,10 +1696,10 @@ func (a *App) SearchPostsForUser(c request.CTX, terms string, userID string, tea
}

func (a *App) GetFileInfosForPostWithMigration(rctx request.CTX, postID string, includeDeleted bool) ([]*model.FileInfo, *model.AppError) {
pchan := make(chan store.GenericStoreResult[*model.Post], 1)
pchan := make(chan store.StoreResult[*model.Post], 1)
go func() {
post, err := a.Srv().Store().Post().GetSingle(postID, includeDeleted)
pchan <- store.GenericStoreResult[*model.Post]{Data: post, NErr: err}
pchan <- store.StoreResult[*model.Post]{Data: post, NErr: err}
close(pchan)
}()

Expand Down
Loading

0 comments on commit edc3057

Please sign in to comment.