MM-17468 - Improve thread fetching (#13653)
* Revert "Thread fetching revert (#13616)"
This reverts commit 8e0fe90897.
* renamed query param for clarity
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
57717a23af
Коммит
597a2b77cd
@@ -66,6 +66,10 @@ func (cfg *AutoPostCreator) UploadTestFile() ([]string, bool) {
|
||||
}
|
||||
|
||||
func (cfg *AutoPostCreator) CreateRandomPost() (*model.Post, bool) {
|
||||
return cfg.CreateRandomPostNested("", "")
|
||||
}
|
||||
|
||||
func (cfg *AutoPostCreator) CreateRandomPostNested(parentId, rootId string) (*model.Post, bool) {
|
||||
var fileIds []string
|
||||
if cfg.HasImage {
|
||||
var err1 bool
|
||||
@@ -84,10 +88,12 @@ func (cfg *AutoPostCreator) CreateRandomPost() (*model.Post, bool) {
|
||||
|
||||
post := &model.Post{
|
||||
ChannelId: cfg.channelid,
|
||||
ParentId: parentId,
|
||||
RootId: rootId,
|
||||
Message: postText,
|
||||
FileIds: fileIds}
|
||||
rpost, err2 := cfg.client.CreatePost(post)
|
||||
if err2 != nil {
|
||||
rpost, resp := cfg.client.CreatePost(post)
|
||||
if resp != nil && resp.Error != nil {
|
||||
return nil, false
|
||||
}
|
||||
return rpost, true
|
||||
|
||||
@@ -502,7 +502,7 @@ func TestAddChannelMemberNoUserRequestor(t *testing.T) {
|
||||
}
|
||||
assert.Equal(t, groupUserIds, channelMemberHistoryUserIds)
|
||||
|
||||
postList, err := th.App.Srv.Store.Post().GetPosts(channel.Id, 0, 1, false)
|
||||
postList, err := th.App.Srv.Store.Post().GetPosts(model.GetPostsOptions{ChannelId: channel.Id, Page: 0, PerPage: 1}, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
if assert.Len(t, postList.Order, 1) {
|
||||
|
||||
@@ -39,6 +39,9 @@ var usage = `Mattermost testing commands to help configure the system
|
||||
Example:
|
||||
/test channels fuzz 5 10
|
||||
|
||||
ThreadedPost - create a large threaded post
|
||||
/test threaded_post
|
||||
|
||||
Posts - Add some random posts with fuzz text to current channel.
|
||||
/test posts [fuzz] <Min Posts> <Max Posts> <Max Images>
|
||||
|
||||
@@ -135,6 +138,10 @@ func (me *LoadTestProvider) DoCommand(a *App, args *model.CommandArgs, message s
|
||||
return me.PostCommand(a, args, message)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(message, "threaded_post") {
|
||||
return me.ThreadedPostCommand(a, args, message)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(message, "url") {
|
||||
return me.UrlCommand(a, args, message)
|
||||
}
|
||||
@@ -301,6 +308,34 @@ func (me *LoadTestProvider) ChannelsCommand(a *App, args *model.CommandArgs, mes
|
||||
return &model.CommandResponse{Text: "Added channels", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
func (me *LoadTestProvider) ThreadedPostCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
var usernames []string
|
||||
options := &model.UserGetOptions{InTeamId: args.TeamId, Page: 0, PerPage: 1000}
|
||||
if profileUsers, err := a.Srv.Store.User().GetProfiles(options); err == nil {
|
||||
usernames = make([]string, len(profileUsers))
|
||||
i := 0
|
||||
for _, userprof := range profileUsers {
|
||||
usernames[i] = userprof.Username
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
client := model.NewAPIv4Client(args.SiteURL)
|
||||
client.MockSession(args.Session.Token)
|
||||
testPoster := NewAutoPostCreator(client, args.ChannelId)
|
||||
testPoster.Fuzzy = true
|
||||
testPoster.Users = usernames
|
||||
rpost, ok := testPoster.CreateRandomPost()
|
||||
if !ok {
|
||||
return &model.CommandResponse{Text: "Cannot create a post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
for i := 0; i < 1000; i++ {
|
||||
testPoster.CreateRandomPostNested(rpost.Id, rpost.Id)
|
||||
}
|
||||
|
||||
return &model.CommandResponse{Text: "Added threaded post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
func (me *LoadTestProvider) PostsCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
cmd := strings.TrimSpace(strings.TrimPrefix(message, "posts"))
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
||||
fileMigrationLock.Lock()
|
||||
defer fileMigrationLock.Unlock()
|
||||
|
||||
result, err := a.Srv.Store.Post().Get(post.Id)
|
||||
result, err := a.Srv.Store.Post().Get(post.Id, false)
|
||||
if err != nil {
|
||||
mlog.Error("Unable to get post when migrating post to use FileInfos", mlog.Err(err), mlog.String("post_id", post.Id))
|
||||
return []*model.FileInfo{}
|
||||
|
||||
@@ -501,7 +501,7 @@ func (api *PluginAPI) DeletePost(postId string) *model.AppError {
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetPostThread(postId string) (*model.PostList, *model.AppError) {
|
||||
return api.app.GetPostThread(postId)
|
||||
return api.app.GetPostThread(postId, false)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetPost(postId string) (*model.Post, *model.AppError) {
|
||||
@@ -509,19 +509,19 @@ func (api *PluginAPI) GetPost(postId string) (*model.Post, *model.AppError) {
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError) {
|
||||
return api.app.GetPostsSince(channelId, time)
|
||||
return api.app.GetPostsSince(model.GetPostsSinceOptions{ChannelId: channelId, Time: time})
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetPostsAfter(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
||||
return api.app.GetPostsAfterPost(channelId, postId, page, perPage)
|
||||
return api.app.GetPostsAfterPost(model.GetPostsOptions{ChannelId: channelId, PostId: postId, Page: page, PerPage: perPage})
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetPostsBefore(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
||||
return api.app.GetPostsBeforePost(channelId, postId, page, perPage)
|
||||
return api.app.GetPostsBeforePost(model.GetPostsOptions{ChannelId: channelId, PostId: postId, Page: page, PerPage: perPage})
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetPostsForChannel(channelId string, page, perPage int) (*model.PostList, *model.AppError) {
|
||||
return api.app.GetPostsPage(channelId, page, perPage)
|
||||
return api.app.GetPostsPage(model.GetPostsOptions{ChannelId: channelId, Page: perPage, PerPage: page})
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdatePost(post *model.Post) (*model.Post, *model.AppError) {
|
||||
|
||||
52
app/post.go
52
app/post.go
@@ -167,7 +167,7 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
|
||||
if len(post.RootId) > 0 {
|
||||
pchan = make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
r, pErr := a.Srv.Store.Post().Get(post.RootId)
|
||||
r, pErr := a.Srv.Store.Post().Get(post.RootId, false)
|
||||
pchan <- store.StoreResult{Data: r, Err: pErr}
|
||||
close(pchan)
|
||||
}()
|
||||
@@ -475,7 +475,7 @@ func (a *App) DeleteEphemeralPost(userId, postId string) {
|
||||
func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError) {
|
||||
post.SanitizeProps()
|
||||
|
||||
postLists, err := a.Srv.Store.Post().Get(post.Id)
|
||||
postLists, err := a.Srv.Store.Post().Get(post.Id, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -614,28 +614,28 @@ func (a *App) PatchPost(postId string, patch *model.PostPatch) (*model.Post, *mo
|
||||
return updatedPost, nil
|
||||
}
|
||||
|
||||
func (a *App) GetPostsPage(channelId string, page int, perPage int) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Post().GetPosts(channelId, page*perPage, perPage, true)
|
||||
func (a *App) GetPostsPage(options model.GetPostsOptions) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Post().GetPosts(options, false)
|
||||
}
|
||||
|
||||
func (a *App) GetPosts(channelId string, offset int, limit int) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Post().GetPosts(channelId, offset, limit, true)
|
||||
return a.Srv.Store.Post().GetPosts(model.GetPostsOptions{ChannelId: channelId, Page: offset, PerPage: limit}, true)
|
||||
}
|
||||
|
||||
func (a *App) GetPostsEtag(channelId string) string {
|
||||
return a.Srv.Store.Post().GetEtag(channelId, true)
|
||||
}
|
||||
|
||||
func (a *App) GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Post().GetPostsSince(channelId, time, true)
|
||||
func (a *App) GetPostsSince(options model.GetPostsSinceOptions) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Post().GetPostsSince(options, true)
|
||||
}
|
||||
|
||||
func (a *App) GetSinglePost(postId string) (*model.Post, *model.AppError) {
|
||||
return a.Srv.Store.Post().GetSingle(postId)
|
||||
}
|
||||
|
||||
func (a *App) GetPostThread(postId string) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Post().Get(postId)
|
||||
func (a *App) GetPostThread(postId string, skipFetchThreads bool) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Post().Get(postId, skipFetchThreads)
|
||||
}
|
||||
|
||||
func (a *App) GetFlaggedPosts(userId string, offset int, limit int) (*model.PostList, *model.AppError) {
|
||||
@@ -651,7 +651,7 @@ func (a *App) GetFlaggedPostsForChannel(userId, channelId string, offset int, li
|
||||
}
|
||||
|
||||
func (a *App) GetPermalinkPost(postId string, userId string) (*model.PostList, *model.AppError) {
|
||||
list, err := a.Srv.Store.Post().Get(postId)
|
||||
list, err := a.Srv.Store.Post().Get(postId, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -673,19 +673,19 @@ func (a *App) GetPermalinkPost(postId string, userId string) (*model.PostList, *
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (a *App) GetPostsBeforePost(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Post().GetPostsBefore(channelId, postId, perPage, page*perPage)
|
||||
func (a *App) GetPostsBeforePost(options model.GetPostsOptions) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Post().GetPostsBefore(options)
|
||||
}
|
||||
|
||||
func (a *App) GetPostsAfterPost(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Post().GetPostsAfter(channelId, postId, perPage, page*perPage)
|
||||
func (a *App) GetPostsAfterPost(options model.GetPostsOptions) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Post().GetPostsAfter(options)
|
||||
}
|
||||
|
||||
func (a *App) GetPostsAroundPost(postId, channelId string, offset, limit int, before bool) (*model.PostList, *model.AppError) {
|
||||
func (a *App) GetPostsAroundPost(before bool, options model.GetPostsOptions) (*model.PostList, *model.AppError) {
|
||||
if before {
|
||||
return a.Srv.Store.Post().GetPostsBefore(channelId, postId, limit, offset)
|
||||
return a.Srv.Store.Post().GetPostsBefore(options)
|
||||
}
|
||||
return a.Srv.Store.Post().GetPostsAfter(channelId, postId, limit, offset)
|
||||
return a.Srv.Store.Post().GetPostsAfter(options)
|
||||
}
|
||||
|
||||
func (a *App) GetPostAfterTime(channelId string, time int64) (*model.Post, *model.AppError) {
|
||||
@@ -773,8 +773,7 @@ func (a *App) AddCursorIdsForPostList(originalList *model.PostList, afterPost, b
|
||||
originalList.NextPostId = nextPostId
|
||||
originalList.PrevPostId = prevPostId
|
||||
}
|
||||
|
||||
func (a *App) GetPostsForChannelAroundLastUnread(channelId, userId string, limitBefore, limitAfter int) (*model.PostList, *model.AppError) {
|
||||
func (a *App) GetPostsForChannelAroundLastUnread(channelId, userId string, limitBefore, limitAfter int, skipFetchThreads bool) (*model.PostList, *model.AppError) {
|
||||
var member *model.ChannelMember
|
||||
var err *model.AppError
|
||||
if member, err = a.GetChannelMember(channelId, userId); err != nil {
|
||||
@@ -790,7 +789,7 @@ func (a *App) GetPostsForChannelAroundLastUnread(channelId, userId string, limit
|
||||
return model.NewPostList(), nil
|
||||
}
|
||||
|
||||
postList, err := a.GetPostThread(lastUnreadPostId)
|
||||
postList, err := a.GetPostThread(lastUnreadPostId, skipFetchThreads)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -798,13 +797,13 @@ func (a *App) GetPostsForChannelAroundLastUnread(channelId, userId string, limit
|
||||
// channel organically, those replies will be added below.
|
||||
postList.Order = []string{lastUnreadPostId}
|
||||
|
||||
if postListBefore, err := a.GetPostsBeforePost(channelId, lastUnreadPostId, PAGE_DEFAULT, limitBefore); err != nil {
|
||||
if postListBefore, err := a.GetPostsBeforePost(model.GetPostsOptions{ChannelId: channelId, PostId: lastUnreadPostId, Page: PAGE_DEFAULT, PerPage: limitBefore, SkipFetchThreads: skipFetchThreads}); err != nil {
|
||||
return nil, err
|
||||
} else if postListBefore != nil {
|
||||
postList.Extend(postListBefore)
|
||||
}
|
||||
|
||||
if postListAfter, err := a.GetPostsAfterPost(channelId, lastUnreadPostId, PAGE_DEFAULT, limitAfter-1); err != nil {
|
||||
if postListAfter, err := a.GetPostsAfterPost(model.GetPostsOptions{ChannelId: channelId, PostId: lastUnreadPostId, Page: PAGE_DEFAULT, PerPage: limitAfter - 1, SkipFetchThreads: skipFetchThreads}); err != nil {
|
||||
return nil, err
|
||||
} else if postListAfter != nil {
|
||||
postList.Extend(postListAfter)
|
||||
@@ -1216,7 +1215,7 @@ func (a *App) countMentionsFromPost(user *model.User, post *model.Post) (int, *m
|
||||
// A mapping of thread root IDs to whether or not a post in that thread mentions the user
|
||||
mentionedByThread := make(map[string]bool)
|
||||
|
||||
thread, err := a.GetPostThread(post.Id)
|
||||
thread, err := a.GetPostThread(post.Id, false)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -1230,7 +1229,12 @@ func (a *App) countMentionsFromPost(user *model.User, post *model.Post) (int, *m
|
||||
page := 0
|
||||
perPage := 200
|
||||
for {
|
||||
postList, err := a.GetPostsAfterPost(post.ChannelId, post.Id, page, perPage)
|
||||
postList, err := a.GetPostsAfterPost(model.GetPostsOptions{
|
||||
ChannelId: post.ChannelId,
|
||||
PostId: post.Id,
|
||||
Page: page,
|
||||
PerPage: perPage,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user