Move Thread.GetPosts to PostStore.GetPostsByThread (#21633)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ab5137395c
Коммит
98e685f07c
@@ -1685,7 +1685,7 @@ func (a *App) countThreadMentions(c request.CTX, user *model.User, post *model.P
|
|||||||
true, // Assume channel mentions are always allowed for simplicity
|
true, // Assume channel mentions are always allowed for simplicity
|
||||||
)
|
)
|
||||||
|
|
||||||
posts, nErr := a.Srv().Store().Thread().GetPosts(post.Id, timestamp)
|
posts, nErr := a.Srv().Store().Post().GetPostsByThread(post.Id, timestamp)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
return 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
return 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6089,6 +6089,24 @@ func (s *OpenTracingLayerPostStore) GetPostsByIds(postIds []string) ([]*model.Po
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *OpenTracingLayerPostStore) GetPostsByThread(threadID string, since int64) ([]*model.Post, error) {
|
||||||
|
origCtx := s.Root.Store.Context()
|
||||||
|
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetPostsByThread")
|
||||||
|
s.Root.Store.SetContext(newCtx)
|
||||||
|
defer func() {
|
||||||
|
s.Root.Store.SetContext(origCtx)
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer span.Finish()
|
||||||
|
result, err := s.PostStore.GetPostsByThread(threadID, since)
|
||||||
|
if err != nil {
|
||||||
|
span.LogFields(spanlog.Error(err))
|
||||||
|
ext.Error.Set(span, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
func (s *OpenTracingLayerPostStore) GetPostsCreatedAt(channelID string, timestamp int64) ([]*model.Post, error) {
|
func (s *OpenTracingLayerPostStore) GetPostsCreatedAt(channelID string, timestamp int64) ([]*model.Post, error) {
|
||||||
origCtx := s.Root.Store.Context()
|
origCtx := s.Root.Store.Context()
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetPostsCreatedAt")
|
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetPostsCreatedAt")
|
||||||
@@ -9836,24 +9854,6 @@ func (s *OpenTracingLayerThreadStore) GetMembershipsForUser(userId string, teamI
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OpenTracingLayerThreadStore) GetPosts(threadID string, since int64) ([]*model.Post, error) {
|
|
||||||
origCtx := s.Root.Store.Context()
|
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ThreadStore.GetPosts")
|
|
||||||
s.Root.Store.SetContext(newCtx)
|
|
||||||
defer func() {
|
|
||||||
s.Root.Store.SetContext(origCtx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
defer span.Finish()
|
|
||||||
result, err := s.ThreadStore.GetPosts(threadID, since)
|
|
||||||
if err != nil {
|
|
||||||
span.LogFields(spanlog.Error(err))
|
|
||||||
ext.Error.Set(span, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *OpenTracingLayerThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string) (map[string]*model.TeamUnread, error) {
|
func (s *OpenTracingLayerThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string) (map[string]*model.TeamUnread, error) {
|
||||||
origCtx := s.Root.Store.Context()
|
origCtx := s.Root.Store.Context()
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ThreadStore.GetTeamsUnreadForUser")
|
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ThreadStore.GetTeamsUnreadForUser")
|
||||||
|
|||||||
@@ -6900,6 +6900,27 @@ func (s *RetryLayerPostStore) GetPostsByIds(postIds []string) ([]*model.Post, er
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *RetryLayerPostStore) GetPostsByThread(threadID string, since int64) ([]*model.Post, error) {
|
||||||
|
|
||||||
|
tries := 0
|
||||||
|
for {
|
||||||
|
result, err := s.PostStore.GetPostsByThread(threadID, since)
|
||||||
|
if err == nil {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
if !isRepeatableError(err) {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
tries++
|
||||||
|
if tries >= 3 {
|
||||||
|
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
timepkg.Sleep(100 * timepkg.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (s *RetryLayerPostStore) GetPostsCreatedAt(channelID string, timestamp int64) ([]*model.Post, error) {
|
func (s *RetryLayerPostStore) GetPostsCreatedAt(channelID string, timestamp int64) ([]*model.Post, error) {
|
||||||
|
|
||||||
tries := 0
|
tries := 0
|
||||||
@@ -11244,27 +11265,6 @@ func (s *RetryLayerThreadStore) GetMembershipsForUser(userId string, teamID stri
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RetryLayerThreadStore) GetPosts(threadID string, since int64) ([]*model.Post, error) {
|
|
||||||
|
|
||||||
tries := 0
|
|
||||||
for {
|
|
||||||
result, err := s.ThreadStore.GetPosts(threadID, since)
|
|
||||||
if err == nil {
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
if !isRepeatableError(err) {
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
tries++
|
|
||||||
if tries >= 3 {
|
|
||||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
timepkg.Sleep(100 * timepkg.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RetryLayerThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string) (map[string]*model.TeamUnread, error) {
|
func (s *RetryLayerThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string) (map[string]*model.TeamUnread, error) {
|
||||||
|
|
||||||
tries := 0
|
tries := 0
|
||||||
|
|||||||
@@ -1400,6 +1400,23 @@ func (s *SqlPostStore) GetPostsAfter(options model.GetPostsOptions, sanitizeOpti
|
|||||||
return s.getPostsAround(false, options, sanitizeOptions)
|
return s.getPostsAround(false, options, sanitizeOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SqlPostStore) GetPostsByThread(threadId string, since int64) ([]*model.Post, error) {
|
||||||
|
query := s.getQueryBuilder().
|
||||||
|
Select("*").
|
||||||
|
From("Posts").
|
||||||
|
Where(sq.Eq{"RootId": threadId}).
|
||||||
|
Where(sq.Eq{"DeleteAt": 0}).
|
||||||
|
Where(sq.GtOrEq{"CreateAt": since})
|
||||||
|
|
||||||
|
result := []*model.Post{}
|
||||||
|
err := s.GetReplicaX().SelectBuilder(&result, query)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to fetch thread posts")
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions, sanitizeOptions map[string]bool) (*model.PostList, error) {
|
func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions, sanitizeOptions map[string]bool) (*model.PostList, error) {
|
||||||
if options.Page < 0 {
|
if options.Page < 0 {
|
||||||
return nil, store.NewErrInvalidInput("Post", "<options.Page>", options.Page)
|
return nil, store.NewErrInvalidInput("Post", "<options.Page>", options.Page)
|
||||||
|
|||||||
@@ -779,23 +779,6 @@ func (s *SqlThreadStore) MaintainMembership(userId, postId string, opts store.Th
|
|||||||
return membership, err
|
return membership, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlThreadStore) GetPosts(threadId string, since int64) ([]*model.Post, error) {
|
|
||||||
query := s.getQueryBuilder().
|
|
||||||
Select("*").
|
|
||||||
From("Posts").
|
|
||||||
Where(sq.Eq{"RootId": threadId}).
|
|
||||||
Where(sq.Eq{"DeleteAt": 0}).
|
|
||||||
Where(sq.GtOrEq{"CreateAt": since})
|
|
||||||
|
|
||||||
result := []*model.Post{}
|
|
||||||
err := s.GetReplicaX().SelectBuilder(&result, query)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "failed to fetch thread posts")
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// PermanentDeleteBatchForRetentionPolicies deletes a batch of records which are affected by
|
// PermanentDeleteBatchForRetentionPolicies deletes a batch of records which are affected by
|
||||||
// the global or a granular retention policy.
|
// the global or a granular retention policy.
|
||||||
// See `genericPermanentDeleteBatchForRetentionPolicies` for details.
|
// See `genericPermanentDeleteBatchForRetentionPolicies` for details.
|
||||||
|
|||||||
@@ -325,7 +325,6 @@ type ThreadStore interface {
|
|||||||
GetThreadsForUser(userId, teamID string, opts model.GetUserThreadsOpts) ([]*model.ThreadResponse, error)
|
GetThreadsForUser(userId, teamID string, opts model.GetUserThreadsOpts) ([]*model.ThreadResponse, error)
|
||||||
GetThreadForUser(threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error)
|
GetThreadForUser(threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error)
|
||||||
GetTeamsUnreadForUser(userID string, teamIDs []string) (map[string]*model.TeamUnread, error)
|
GetTeamsUnreadForUser(userID string, teamIDs []string) (map[string]*model.TeamUnread, error)
|
||||||
GetPosts(threadID string, since int64) ([]*model.Post, error)
|
|
||||||
|
|
||||||
MarkAllAsRead(userID string, threadIds []string) error
|
MarkAllAsRead(userID string, threadIds []string) error
|
||||||
MarkAllAsReadByTeam(userID, teamID string) error
|
MarkAllAsReadByTeam(userID, teamID string) error
|
||||||
@@ -364,6 +363,7 @@ type PostStore interface {
|
|||||||
GetPostsBefore(options model.GetPostsOptions, sanitizeOptions map[string]bool) (*model.PostList, error)
|
GetPostsBefore(options model.GetPostsOptions, sanitizeOptions map[string]bool) (*model.PostList, error)
|
||||||
GetPostsAfter(options model.GetPostsOptions, sanitizeOptions map[string]bool) (*model.PostList, error)
|
GetPostsAfter(options model.GetPostsOptions, sanitizeOptions map[string]bool) (*model.PostList, error)
|
||||||
GetPostsSince(options model.GetPostsSinceOptions, allowFromCache bool, sanitizeOptions map[string]bool) (*model.PostList, error)
|
GetPostsSince(options model.GetPostsSinceOptions, allowFromCache bool, sanitizeOptions map[string]bool) (*model.PostList, error)
|
||||||
|
GetPostsByThread(threadID string, since int64) ([]*model.Post, error)
|
||||||
GetPostAfterTime(channelID string, timestamp int64, collapsedThreads bool) (*model.Post, error)
|
GetPostAfterTime(channelID string, timestamp int64, collapsedThreads bool) (*model.Post, error)
|
||||||
GetPostIdAfterTime(channelID string, timestamp int64, collapsedThreads bool) (string, error)
|
GetPostIdAfterTime(channelID string, timestamp int64, collapsedThreads bool) (string, error)
|
||||||
GetPostIdBeforeTime(channelID string, timestamp int64, collapsedThreads bool) (string, error)
|
GetPostIdBeforeTime(channelID string, timestamp int64, collapsedThreads bool) (string, error)
|
||||||
|
|||||||
@@ -603,6 +603,29 @@ func (_m *PostStore) GetPostsByIds(postIds []string) ([]*model.Post, error) {
|
|||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPostsByThread provides a mock function with given fields: threadID, since
|
||||||
|
func (_m *PostStore) GetPostsByThread(threadID string, since int64) ([]*model.Post, error) {
|
||||||
|
ret := _m.Called(threadID, since)
|
||||||
|
|
||||||
|
var r0 []*model.Post
|
||||||
|
if rf, ok := ret.Get(0).(func(string, int64) []*model.Post); ok {
|
||||||
|
r0 = rf(threadID, since)
|
||||||
|
} else {
|
||||||
|
if ret.Get(0) != nil {
|
||||||
|
r0 = ret.Get(0).([]*model.Post)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var r1 error
|
||||||
|
if rf, ok := ret.Get(1).(func(string, int64) error); ok {
|
||||||
|
r1 = rf(threadID, since)
|
||||||
|
} else {
|
||||||
|
r1 = ret.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
||||||
// GetPostsCreatedAt provides a mock function with given fields: channelID, timestamp
|
// GetPostsCreatedAt provides a mock function with given fields: channelID, timestamp
|
||||||
func (_m *PostStore) GetPostsCreatedAt(channelID string, timestamp int64) ([]*model.Post, error) {
|
func (_m *PostStore) GetPostsCreatedAt(channelID string, timestamp int64) ([]*model.Post, error) {
|
||||||
ret := _m.Called(channelID, timestamp)
|
ret := _m.Called(channelID, timestamp)
|
||||||
|
|||||||
@@ -119,29 +119,6 @@ func (_m *ThreadStore) GetMembershipsForUser(userId string, teamID string) ([]*m
|
|||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPosts provides a mock function with given fields: threadID, since
|
|
||||||
func (_m *ThreadStore) GetPosts(threadID string, since int64) ([]*model.Post, error) {
|
|
||||||
ret := _m.Called(threadID, since)
|
|
||||||
|
|
||||||
var r0 []*model.Post
|
|
||||||
if rf, ok := ret.Get(0).(func(string, int64) []*model.Post); ok {
|
|
||||||
r0 = rf(threadID, since)
|
|
||||||
} else {
|
|
||||||
if ret.Get(0) != nil {
|
|
||||||
r0 = ret.Get(0).([]*model.Post)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var r1 error
|
|
||||||
if rf, ok := ret.Get(1).(func(string, int64) error); ok {
|
|
||||||
r1 = rf(threadID, since)
|
|
||||||
} else {
|
|
||||||
r1 = ret.Error(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return r0, r1
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTeamsUnreadForUser provides a mock function with given fields: userID, teamIDs
|
// GetTeamsUnreadForUser provides a mock function with given fields: userID, teamIDs
|
||||||
func (_m *ThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string) (map[string]*model.TeamUnread, error) {
|
func (_m *ThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string) (map[string]*model.TeamUnread, error) {
|
||||||
ret := _m.Called(userID, teamIDs)
|
ret := _m.Called(userID, teamIDs)
|
||||||
|
|||||||
@@ -5508,6 +5508,22 @@ func (s *TimerLayerPostStore) GetPostsByIds(postIds []string) ([]*model.Post, er
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *TimerLayerPostStore) GetPostsByThread(threadID string, since int64) ([]*model.Post, error) {
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
|
result, err := s.PostStore.GetPostsByThread(threadID, since)
|
||||||
|
|
||||||
|
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||||
|
if s.Root.Metrics != nil {
|
||||||
|
success := "false"
|
||||||
|
if err == nil {
|
||||||
|
success = "true"
|
||||||
|
}
|
||||||
|
s.Root.Metrics.ObserveStoreMethodDuration("PostStore.GetPostsByThread", success, elapsed)
|
||||||
|
}
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
func (s *TimerLayerPostStore) GetPostsCreatedAt(channelID string, timestamp int64) ([]*model.Post, error) {
|
func (s *TimerLayerPostStore) GetPostsCreatedAt(channelID string, timestamp int64) ([]*model.Post, error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
@@ -8849,22 +8865,6 @@ func (s *TimerLayerThreadStore) GetMembershipsForUser(userId string, teamID stri
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TimerLayerThreadStore) GetPosts(threadID string, since int64) ([]*model.Post, error) {
|
|
||||||
start := time.Now()
|
|
||||||
|
|
||||||
result, err := s.ThreadStore.GetPosts(threadID, since)
|
|
||||||
|
|
||||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
|
||||||
if s.Root.Metrics != nil {
|
|
||||||
success := "false"
|
|
||||||
if err == nil {
|
|
||||||
success = "true"
|
|
||||||
}
|
|
||||||
s.Root.Metrics.ObserveStoreMethodDuration("ThreadStore.GetPosts", success, elapsed)
|
|
||||||
}
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *TimerLayerThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string) (map[string]*model.TeamUnread, error) {
|
func (s *TimerLayerThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string) (map[string]*model.TeamUnread, error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user