MM-30304 - Handle collapsed threads in page apis (#17064)

Этот коммит содержится в:
Eli Yukelzon
2021-03-05 09:46:36 +02:00
коммит произвёл GitHub
родитель f2e27a39da
Коммит 4aa6c863c3
11 изменённых файлов: 110 добавлений и 103 удалений

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

@@ -210,7 +210,7 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
}
c.App.AddCursorIdsForPostList(list, afterPost, beforePost, since, page, perPage)
c.App.AddCursorIdsForPostList(list, afterPost, beforePost, since, page, perPage, collapsedThreads)
clientPostList := c.App.PreparePostListForClient(list)
w.Write([]byte(clientPostList.ToJson()))
@@ -264,8 +264,8 @@ func getPostsForChannelAroundLastUnread(c *Context, w http.ResponseWriter, r *ht
}
}
postList.NextPostId = c.App.GetNextPostIdFromPostList(postList)
postList.PrevPostId = c.App.GetPrevPostIdFromPostList(postList)
postList.NextPostId = c.App.GetNextPostIdFromPostList(postList, collapsedThreads)
postList.PrevPostId = c.App.GetPrevPostIdFromPostList(postList, collapsedThreads)
clientPostList := c.App.PreparePostListForClient(postList)

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

@@ -44,7 +44,7 @@ type AppIface interface {
// AddCursorIdsForPostList adds NextPostId and PrevPostId as cursor to the PostList.
// The conditional blocks ensure that it sets those cursor IDs immediately as afterPost, beforePost or empty,
// and only query to database whenever necessary.
AddCursorIdsForPostList(originalList *model.PostList, afterPost, beforePost string, since int64, page, perPage int)
AddCursorIdsForPostList(originalList *model.PostList, afterPost, beforePost string, since int64, page, perPage int, collapsedThreads bool)
// AddPublicKey will add plugin public key to the config. Overwrites the previous file
AddPublicKey(name string, key io.Reader) *model.AppError
// Caller must close the first return value
@@ -610,7 +610,7 @@ type AppIface interface {
GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFunc) string
GetMultipleEmojiByName(names []string) ([]*model.Emoji, *model.AppError)
GetNewUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
GetNextPostIdFromPostList(postList *model.PostList) string
GetNextPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string
GetNotificationNameFormat(user *model.User) string
GetNumberOfChannelsOnTeam(teamID string) (int, *model.AppError)
GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError)
@@ -636,9 +636,9 @@ type AppIface interface {
GetPinnedPosts(channelID string) (*model.PostList, *model.AppError)
GetPluginKey(pluginID string, key string) ([]byte, *model.AppError)
GetPlugins() (*model.PluginsResponse, *model.AppError)
GetPostAfterTime(channelID string, time int64) (*model.Post, *model.AppError)
GetPostIdAfterTime(channelID string, time int64) (string, *model.AppError)
GetPostIdBeforeTime(channelID string, time int64) (string, *model.AppError)
GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, *model.AppError)
GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError)
GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError)
GetPostThread(postID string, skipFetchThreads, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError)
GetPosts(channelID string, offset int, limit int) (*model.PostList, *model.AppError)
GetPostsAfterPost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
@@ -651,7 +651,7 @@ type AppIface interface {
GetPreferenceByCategoryAndNameForUser(userID string, category string, preferenceName string) (*model.Preference, *model.AppError)
GetPreferenceByCategoryForUser(userID string, category string) (model.Preferences, *model.AppError)
GetPreferencesForUser(userID string) (model.Preferences, *model.AppError)
GetPrevPostIdFromPostList(postList *model.PostList) string
GetPrevPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string
GetPrivateChannelsForTeam(teamID string, offset int, limit int) (*model.ChannelList, *model.AppError)
GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
GetPublicChannelsByIdsForTeam(teamID string, channelIDs []string) (*model.ChannelList, *model.AppError)

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

@@ -132,7 +132,7 @@ func (a *OpenTracingAppLayer) AddConfigListener(listener func(*model.Config, *mo
return resultVar0
}
func (a *OpenTracingAppLayer) AddCursorIdsForPostList(originalList *model.PostList, afterPost string, beforePost string, since int64, page int, perPage int) {
func (a *OpenTracingAppLayer) AddCursorIdsForPostList(originalList *model.PostList, afterPost string, beforePost string, since int64, page int, perPage int, collapsedThreads bool) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.AddCursorIdsForPostList")
@@ -144,7 +144,7 @@ func (a *OpenTracingAppLayer) AddCursorIdsForPostList(originalList *model.PostLi
}()
defer span.Finish()
a.app.AddCursorIdsForPostList(originalList, afterPost, beforePost, since, page, perPage)
a.app.AddCursorIdsForPostList(originalList, afterPost, beforePost, since, page, perPage, collapsedThreads)
}
func (a *OpenTracingAppLayer) AddDirectChannels(teamID string, user *model.User) *model.AppError {
@@ -6432,7 +6432,7 @@ func (a *OpenTracingAppLayer) GetNewUsersForTeamPage(teamID string, page int, pe
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetNextPostIdFromPostList(postList *model.PostList) string {
func (a *OpenTracingAppLayer) GetNextPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetNextPostIdFromPostList")
@@ -6444,7 +6444,7 @@ func (a *OpenTracingAppLayer) GetNextPostIdFromPostList(postList *model.PostList
}()
defer span.Finish()
resultVar0 := a.app.GetNextPostIdFromPostList(postList)
resultVar0 := a.app.GetNextPostIdFromPostList(postList, collapsedThreads)
return resultVar0
}
@@ -7072,7 +7072,7 @@ func (a *OpenTracingAppLayer) GetPluginsEnvironment() *plugin.Environment {
return resultVar0
}
func (a *OpenTracingAppLayer) GetPostAfterTime(channelID string, time int64) (*model.Post, *model.AppError) {
func (a *OpenTracingAppLayer) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetPostAfterTime")
@@ -7084,7 +7084,7 @@ func (a *OpenTracingAppLayer) GetPostAfterTime(channelID string, time int64) (*m
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.GetPostAfterTime(channelID, time)
resultVar0, resultVar1 := a.app.GetPostAfterTime(channelID, time, collapsedThreads)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@@ -7094,7 +7094,7 @@ func (a *OpenTracingAppLayer) GetPostAfterTime(channelID string, time int64) (*m
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetPostIdAfterTime(channelID string, time int64) (string, *model.AppError) {
func (a *OpenTracingAppLayer) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetPostIdAfterTime")
@@ -7106,7 +7106,7 @@ func (a *OpenTracingAppLayer) GetPostIdAfterTime(channelID string, time int64) (
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.GetPostIdAfterTime(channelID, time)
resultVar0, resultVar1 := a.app.GetPostIdAfterTime(channelID, time, collapsedThreads)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@@ -7116,7 +7116,7 @@ func (a *OpenTracingAppLayer) GetPostIdAfterTime(channelID string, time int64) (
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetPostIdBeforeTime(channelID string, time int64) (string, *model.AppError) {
func (a *OpenTracingAppLayer) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetPostIdBeforeTime")
@@ -7128,7 +7128,7 @@ func (a *OpenTracingAppLayer) GetPostIdBeforeTime(channelID string, time int64)
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.GetPostIdBeforeTime(channelID, time)
resultVar0, resultVar1 := a.app.GetPostIdBeforeTime(channelID, time, collapsedThreads)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@@ -7397,7 +7397,7 @@ func (a *OpenTracingAppLayer) GetPreferencesForUser(userID string) (model.Prefer
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetPrevPostIdFromPostList(postList *model.PostList) string {
func (a *OpenTracingAppLayer) GetPrevPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetPrevPostIdFromPostList")
@@ -7409,7 +7409,7 @@ func (a *OpenTracingAppLayer) GetPrevPostIdFromPostList(postList *model.PostList
}()
defer span.Finish()
resultVar0 := a.app.GetPrevPostIdFromPostList(postList)
resultVar0 := a.app.GetPrevPostIdFromPostList(postList, collapsedThreads)
return resultVar0
}

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

@@ -876,8 +876,8 @@ func (a *App) GetPostsAroundPost(before bool, options model.GetPostsOptions) (*m
return postList, nil
}
func (a *App) GetPostAfterTime(channelID string, time int64) (*model.Post, *model.AppError) {
post, err := a.Srv().Store.Post().GetPostAfterTime(channelID, time)
func (a *App) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, *model.AppError) {
post, err := a.Srv().Store.Post().GetPostAfterTime(channelID, time, collapsedThreads)
if err != nil {
return nil, model.NewAppError("GetPostAfterTime", "app.post.get_post_after_time.app_error", nil, err.Error(), http.StatusInternalServerError)
}
@@ -885,8 +885,8 @@ func (a *App) GetPostAfterTime(channelID string, time int64) (*model.Post, *mode
return post, nil
}
func (a *App) GetPostIdAfterTime(channelID string, time int64) (string, *model.AppError) {
postID, err := a.Srv().Store.Post().GetPostIdAfterTime(channelID, time)
func (a *App) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError) {
postID, err := a.Srv().Store.Post().GetPostIdAfterTime(channelID, time, collapsedThreads)
if err != nil {
return "", model.NewAppError("GetPostIdAfterTime", "app.post.get_post_id_around.app_error", nil, err.Error(), http.StatusInternalServerError)
}
@@ -894,8 +894,8 @@ func (a *App) GetPostIdAfterTime(channelID string, time int64) (string, *model.A
return postID, nil
}
func (a *App) GetPostIdBeforeTime(channelID string, time int64) (string, *model.AppError) {
postID, err := a.Srv().Store.Post().GetPostIdBeforeTime(channelID, time)
func (a *App) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError) {
postID, err := a.Srv().Store.Post().GetPostIdBeforeTime(channelID, time, collapsedThreads)
if err != nil {
return "", model.NewAppError("GetPostIdBeforeTime", "app.post.get_post_id_around.app_error", nil, err.Error(), http.StatusInternalServerError)
}
@@ -903,11 +903,11 @@ func (a *App) GetPostIdBeforeTime(channelID string, time int64) (string, *model.
return postID, nil
}
func (a *App) GetNextPostIdFromPostList(postList *model.PostList) string {
func (a *App) GetNextPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string {
if len(postList.Order) > 0 {
firstPostId := postList.Order[0]
firstPost := postList.Posts[firstPostId]
nextPostId, err := a.GetPostIdAfterTime(firstPost.ChannelId, firstPost.CreateAt)
nextPostId, err := a.GetPostIdAfterTime(firstPost.ChannelId, firstPost.CreateAt, collapsedThreads)
if err != nil {
mlog.Warn("GetNextPostIdFromPostList: failed in getting next post", mlog.Err(err))
}
@@ -918,11 +918,11 @@ func (a *App) GetNextPostIdFromPostList(postList *model.PostList) string {
return ""
}
func (a *App) GetPrevPostIdFromPostList(postList *model.PostList) string {
func (a *App) GetPrevPostIdFromPostList(postList *model.PostList, collapsedThreads bool) string {
if len(postList.Order) > 0 {
lastPostId := postList.Order[len(postList.Order)-1]
lastPost := postList.Posts[lastPostId]
previousPostId, err := a.GetPostIdBeforeTime(lastPost.ChannelId, lastPost.CreateAt)
previousPostId, err := a.GetPostIdBeforeTime(lastPost.ChannelId, lastPost.CreateAt, collapsedThreads)
if err != nil {
mlog.Warn("GetPrevPostIdFromPostList: failed in getting previous post", mlog.Err(err))
}
@@ -936,7 +936,7 @@ func (a *App) GetPrevPostIdFromPostList(postList *model.PostList) string {
// AddCursorIdsForPostList adds NextPostId and PrevPostId as cursor to the PostList.
// The conditional blocks ensure that it sets those cursor IDs immediately as afterPost, beforePost or empty,
// and only query to database whenever necessary.
func (a *App) AddCursorIdsForPostList(originalList *model.PostList, afterPost, beforePost string, since int64, page, perPage int) {
func (a *App) AddCursorIdsForPostList(originalList *model.PostList, afterPost, beforePost string, since int64, page, perPage int, collapsedThreads bool) {
prevPostIdSet := false
prevPostId := ""
nextPostIdSet := false
@@ -966,11 +966,11 @@ func (a *App) AddCursorIdsForPostList(originalList *model.PostList, afterPost, b
}
if !nextPostIdSet {
nextPostId = a.GetNextPostIdFromPostList(originalList)
nextPostId = a.GetNextPostIdFromPostList(originalList, collapsedThreads)
}
if !prevPostIdSet {
prevPostId = a.GetPrevPostIdFromPostList(originalList)
prevPostId = a.GetPrevPostIdFromPostList(originalList, collapsedThreads)
}
originalList.NextPostId = nextPostId
@@ -985,7 +985,7 @@ func (a *App) GetPostsForChannelAroundLastUnread(channelID, userID string, limit
return model.NewPostList(), nil
}
lastUnreadPostId, err := a.GetPostIdAfterTime(channelID, member.LastViewedAt)
lastUnreadPostId, err := a.GetPostIdAfterTime(channelID, member.LastViewedAt, collapsedThreads)
if err != nil {
return nil, err
} else if lastUnreadPostId == "" {

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

@@ -5112,7 +5112,7 @@ func (s *OpenTracingLayerPostStore) GetParentsForExportAfter(limit int, afterID
return result, err
}
func (s *OpenTracingLayerPostStore) GetPostAfterTime(channelID string, time int64) (*model.Post, error) {
func (s *OpenTracingLayerPostStore) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetPostAfterTime")
s.Root.Store.SetContext(newCtx)
@@ -5121,7 +5121,7 @@ func (s *OpenTracingLayerPostStore) GetPostAfterTime(channelID string, time int6
}()
defer span.Finish()
result, err := s.PostStore.GetPostAfterTime(channelID, time)
result, err := s.PostStore.GetPostAfterTime(channelID, time, collapsedThreads)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@@ -5130,7 +5130,7 @@ func (s *OpenTracingLayerPostStore) GetPostAfterTime(channelID string, time int6
return result, err
}
func (s *OpenTracingLayerPostStore) GetPostIdAfterTime(channelID string, time int64) (string, error) {
func (s *OpenTracingLayerPostStore) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetPostIdAfterTime")
s.Root.Store.SetContext(newCtx)
@@ -5139,7 +5139,7 @@ func (s *OpenTracingLayerPostStore) GetPostIdAfterTime(channelID string, time in
}()
defer span.Finish()
result, err := s.PostStore.GetPostIdAfterTime(channelID, time)
result, err := s.PostStore.GetPostIdAfterTime(channelID, time, collapsedThreads)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)
@@ -5148,7 +5148,7 @@ func (s *OpenTracingLayerPostStore) GetPostIdAfterTime(channelID string, time in
return result, err
}
func (s *OpenTracingLayerPostStore) GetPostIdBeforeTime(channelID string, time int64) (string, error) {
func (s *OpenTracingLayerPostStore) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetPostIdBeforeTime")
s.Root.Store.SetContext(newCtx)
@@ -5157,7 +5157,7 @@ func (s *OpenTracingLayerPostStore) GetPostIdBeforeTime(channelID string, time i
}()
defer span.Finish()
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time)
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time, collapsedThreads)
if err != nil {
span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true)

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

@@ -5514,11 +5514,11 @@ func (s *RetryLayerPostStore) GetParentsForExportAfter(limit int, afterID string
}
func (s *RetryLayerPostStore) GetPostAfterTime(channelID string, time int64) (*model.Post, error) {
func (s *RetryLayerPostStore) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, error) {
tries := 0
for {
result, err := s.PostStore.GetPostAfterTime(channelID, time)
result, err := s.PostStore.GetPostAfterTime(channelID, time, collapsedThreads)
if err == nil {
return result, nil
}
@@ -5534,11 +5534,11 @@ func (s *RetryLayerPostStore) GetPostAfterTime(channelID string, time int64) (*m
}
func (s *RetryLayerPostStore) GetPostIdAfterTime(channelID string, time int64) (string, error) {
func (s *RetryLayerPostStore) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, error) {
tries := 0
for {
result, err := s.PostStore.GetPostIdAfterTime(channelID, time)
result, err := s.PostStore.GetPostIdAfterTime(channelID, time, collapsedThreads)
if err == nil {
return result, nil
}
@@ -5554,11 +5554,11 @@ func (s *RetryLayerPostStore) GetPostIdAfterTime(channelID string, time int64) (
}
func (s *RetryLayerPostStore) GetPostIdBeforeTime(channelID string, time int64) (string, error) {
func (s *RetryLayerPostStore) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, error) {
tries := 0
for {
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time)
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time, collapsedThreads)
if err == nil {
return result, nil
}

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

@@ -1026,15 +1026,15 @@ func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions
return list, nil
}
func (s *SqlPostStore) GetPostIdBeforeTime(channelId string, time int64) (string, error) {
return s.getPostIdAroundTime(channelId, time, true)
func (s *SqlPostStore) GetPostIdBeforeTime(channelId string, time int64, collapsedThreads bool) (string, error) {
return s.getPostIdAroundTime(channelId, time, true, collapsedThreads)
}
func (s *SqlPostStore) GetPostIdAfterTime(channelId string, time int64) (string, error) {
return s.getPostIdAroundTime(channelId, time, false)
func (s *SqlPostStore) GetPostIdAfterTime(channelId string, time int64, collapsedThreads bool) (string, error) {
return s.getPostIdAroundTime(channelId, time, false, collapsedThreads)
}
func (s *SqlPostStore) getPostIdAroundTime(channelId string, time int64, before bool) (string, error) {
func (s *SqlPostStore) getPostIdAroundTime(channelId string, time int64, before bool, collapsedThreads bool) (string, error) {
var direction sq.Sqlizer
var sort string
if before {
@@ -1053,14 +1053,18 @@ func (s *SqlPostStore) getPostIdAroundTime(channelId string, time int64, before
table += " USE INDEX(idx_posts_channel_id_delete_at_create_at)"
}
conditions := sq.And{
direction,
sq.Eq{"ChannelId": channelId},
sq.Eq{"DeleteAt": int(0)},
}
if collapsedThreads {
conditions = sq.And{conditions, sq.Eq{"RootId": ""}}
}
query := s.getQueryBuilder().
Select("Id").
From(table).
Where(sq.And{
direction,
sq.Eq{"ChannelId": channelId},
sq.Eq{"DeleteAt": int(0)},
}).
Where(conditions).
// Adding ChannelId and DeleteAt order columns
// to let mysql choose the "idx_posts_channel_id_delete_at_create_at" index always.
// See MM-23369.
@@ -1082,7 +1086,7 @@ func (s *SqlPostStore) getPostIdAroundTime(channelId string, time int64, before
return postId, nil
}
func (s *SqlPostStore) GetPostAfterTime(channelId string, time int64) (*model.Post, error) {
func (s *SqlPostStore) GetPostAfterTime(channelId string, time int64, collapsedThreads bool) (*model.Post, error) {
table := "Posts"
// We force MySQL to use the right index to prevent it from accidentally
// using the index_merge_intersection optimization.
@@ -1090,15 +1094,18 @@ func (s *SqlPostStore) GetPostAfterTime(channelId string, time int64) (*model.Po
if s.DriverName() == model.DATABASE_DRIVER_MYSQL {
table += " USE INDEX(idx_posts_channel_id_delete_at_create_at)"
}
conditions := sq.And{
sq.Gt{"CreateAt": time},
sq.Eq{"ChannelId": channelId},
sq.Eq{"DeleteAt": int(0)},
}
if collapsedThreads {
conditions = sq.And{conditions, sq.Eq{"RootId": ""}}
}
query := s.getQueryBuilder().
Select("*").
From(table).
Where(sq.And{
sq.Gt{"CreateAt": time},
sq.Eq{"ChannelId": channelId},
sq.Eq{"DeleteAt": int(0)},
}).
Where(conditions).
// Adding ChannelId and DeleteAt order columns
// to let mysql choose the "idx_posts_channel_id_delete_at_create_at" index always.
// See MM-23369.

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

@@ -287,9 +287,9 @@ type PostStore interface {
GetPostsBefore(options model.GetPostsOptions) (*model.PostList, error)
GetPostsAfter(options model.GetPostsOptions) (*model.PostList, error)
GetPostsSince(options model.GetPostsSinceOptions, allowFromCache bool) (*model.PostList, error)
GetPostAfterTime(channelID string, time int64) (*model.Post, error)
GetPostIdAfterTime(channelID string, time int64) (string, error)
GetPostIdBeforeTime(channelID string, time int64) (string, error)
GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, error)
GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, error)
GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, error)
GetEtag(channelID string, allowFromCache bool, collapsedThreads bool) string
Search(teamID string, userId string, params *model.SearchParams) (*model.PostList, error)
AnalyticsUserCountsWithPostsByDay(teamID string) (model.AnalyticsRows, error)

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

@@ -310,13 +310,13 @@ func (_m *PostStore) GetParentsForExportAfter(limit int, afterID string) ([]*mod
return r0, r1
}
// GetPostAfterTime provides a mock function with given fields: channelID, time
func (_m *PostStore) GetPostAfterTime(channelID string, time int64) (*model.Post, error) {
ret := _m.Called(channelID, time)
// GetPostAfterTime provides a mock function with given fields: channelID, time, collapsedThreads
func (_m *PostStore) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, error) {
ret := _m.Called(channelID, time, collapsedThreads)
var r0 *model.Post
if rf, ok := ret.Get(0).(func(string, int64) *model.Post); ok {
r0 = rf(channelID, time)
if rf, ok := ret.Get(0).(func(string, int64, bool) *model.Post); ok {
r0 = rf(channelID, time, collapsedThreads)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Post)
@@ -324,8 +324,8 @@ func (_m *PostStore) GetPostAfterTime(channelID string, time int64) (*model.Post
}
var r1 error
if rf, ok := ret.Get(1).(func(string, int64) error); ok {
r1 = rf(channelID, time)
if rf, ok := ret.Get(1).(func(string, int64, bool) error); ok {
r1 = rf(channelID, time, collapsedThreads)
} else {
r1 = ret.Error(1)
}
@@ -333,20 +333,20 @@ func (_m *PostStore) GetPostAfterTime(channelID string, time int64) (*model.Post
return r0, r1
}
// GetPostIdAfterTime provides a mock function with given fields: channelID, time
func (_m *PostStore) GetPostIdAfterTime(channelID string, time int64) (string, error) {
ret := _m.Called(channelID, time)
// GetPostIdAfterTime provides a mock function with given fields: channelID, time, collapsedThreads
func (_m *PostStore) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, error) {
ret := _m.Called(channelID, time, collapsedThreads)
var r0 string
if rf, ok := ret.Get(0).(func(string, int64) string); ok {
r0 = rf(channelID, time)
if rf, ok := ret.Get(0).(func(string, int64, bool) string); ok {
r0 = rf(channelID, time, collapsedThreads)
} else {
r0 = ret.Get(0).(string)
}
var r1 error
if rf, ok := ret.Get(1).(func(string, int64) error); ok {
r1 = rf(channelID, time)
if rf, ok := ret.Get(1).(func(string, int64, bool) error); ok {
r1 = rf(channelID, time, collapsedThreads)
} else {
r1 = ret.Error(1)
}
@@ -354,20 +354,20 @@ func (_m *PostStore) GetPostIdAfterTime(channelID string, time int64) (string, e
return r0, r1
}
// GetPostIdBeforeTime provides a mock function with given fields: channelID, time
func (_m *PostStore) GetPostIdBeforeTime(channelID string, time int64) (string, error) {
ret := _m.Called(channelID, time)
// GetPostIdBeforeTime provides a mock function with given fields: channelID, time, collapsedThreads
func (_m *PostStore) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, error) {
ret := _m.Called(channelID, time, collapsedThreads)
var r0 string
if rf, ok := ret.Get(0).(func(string, int64) string); ok {
r0 = rf(channelID, time)
if rf, ok := ret.Get(0).(func(string, int64, bool) string); ok {
r0 = rf(channelID, time, collapsedThreads)
} else {
r0 = ret.Get(0).(string)
}
var r1 error
if rf, ok := ret.Get(1).(func(string, int64) error); ok {
r1 = rf(channelID, time)
if rf, ok := ret.Get(1).(func(string, int64, bool) error); ok {
r1 = rf(channelID, time, collapsedThreads)
} else {
r1 = ret.Error(1)
}

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

@@ -1579,39 +1579,39 @@ func testPostStoreGetPostBeforeAfter(t *testing.T, ss store.Store) {
_, err = ss.Post().Save(o2a)
require.NoError(t, err)
rPostId1, err := ss.Post().GetPostIdBeforeTime(channelId, o0a.CreateAt)
rPostId1, err := ss.Post().GetPostIdBeforeTime(channelId, o0a.CreateAt, false)
require.Equal(t, rPostId1, o1.Id, "should return before post o1")
require.NoError(t, err)
rPostId1, err = ss.Post().GetPostIdAfterTime(channelId, o0b.CreateAt)
rPostId1, err = ss.Post().GetPostIdAfterTime(channelId, o0b.CreateAt, false)
require.Equal(t, rPostId1, o2.Id, "should return before post o2")
require.NoError(t, err)
rPost1, err := ss.Post().GetPostAfterTime(channelId, o0b.CreateAt)
rPost1, err := ss.Post().GetPostAfterTime(channelId, o0b.CreateAt, false)
require.Equal(t, rPost1.Id, o2.Id, "should return before post o2")
require.NoError(t, err)
rPostId2, err := ss.Post().GetPostIdBeforeTime(channelId, o0.CreateAt)
rPostId2, err := ss.Post().GetPostIdBeforeTime(channelId, o0.CreateAt, false)
require.Empty(t, rPostId2, "should return no post")
require.NoError(t, err)
rPostId2, err = ss.Post().GetPostIdAfterTime(channelId, o0.CreateAt)
rPostId2, err = ss.Post().GetPostIdAfterTime(channelId, o0.CreateAt, false)
require.Equal(t, rPostId2, o1.Id, "should return before post o1")
require.NoError(t, err)
rPost2, err := ss.Post().GetPostAfterTime(channelId, o0.CreateAt)
rPost2, err := ss.Post().GetPostAfterTime(channelId, o0.CreateAt, false)
require.Equal(t, rPost2.Id, o1.Id, "should return before post o1")
require.NoError(t, err)
rPostId3, err := ss.Post().GetPostIdBeforeTime(channelId, o2a.CreateAt)
rPostId3, err := ss.Post().GetPostIdBeforeTime(channelId, o2a.CreateAt, false)
require.Equal(t, rPostId3, o2.Id, "should return before post o2")
require.NoError(t, err)
rPostId3, err = ss.Post().GetPostIdAfterTime(channelId, o2a.CreateAt)
rPostId3, err = ss.Post().GetPostIdAfterTime(channelId, o2a.CreateAt, false)
require.Empty(t, rPostId3, "should return no post")
require.NoError(t, err)
rPost3, err := ss.Post().GetPostAfterTime(channelId, o2a.CreateAt)
rPost3, err := ss.Post().GetPostAfterTime(channelId, o2a.CreateAt, false)
require.Empty(t, rPost3, "should return no post")
require.NoError(t, err)
}

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

@@ -4636,10 +4636,10 @@ func (s *TimerLayerPostStore) GetParentsForExportAfter(limit int, afterID string
return result, err
}
func (s *TimerLayerPostStore) GetPostAfterTime(channelID string, time int64) (*model.Post, error) {
func (s *TimerLayerPostStore) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, error) {
start := timemodule.Now()
result, err := s.PostStore.GetPostAfterTime(channelID, time)
result, err := s.PostStore.GetPostAfterTime(channelID, time, collapsedThreads)
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
if s.Root.Metrics != nil {
@@ -4652,10 +4652,10 @@ func (s *TimerLayerPostStore) GetPostAfterTime(channelID string, time int64) (*m
return result, err
}
func (s *TimerLayerPostStore) GetPostIdAfterTime(channelID string, time int64) (string, error) {
func (s *TimerLayerPostStore) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, error) {
start := timemodule.Now()
result, err := s.PostStore.GetPostIdAfterTime(channelID, time)
result, err := s.PostStore.GetPostIdAfterTime(channelID, time, collapsedThreads)
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
if s.Root.Metrics != nil {
@@ -4668,10 +4668,10 @@ func (s *TimerLayerPostStore) GetPostIdAfterTime(channelID string, time int64) (
return result, err
}
func (s *TimerLayerPostStore) GetPostIdBeforeTime(channelID string, time int64) (string, error) {
func (s *TimerLayerPostStore) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, error) {
start := timemodule.Now()
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time)
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time, collapsedThreads)
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
if s.Root.Metrics != nil {