Simplify thread_store/GetThreadForUser (#21588)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
534a9bcbf0
Коммит
b9d00a1f28
@@ -3033,7 +3033,7 @@ func TestSetPostUnreadWithoutCollapsedThreads(t *testing.T) {
|
||||
|
||||
threadMembership, appErr := th.App.GetThreadMembershipForUser(th.BasicUser.Id, rootPost1.Id)
|
||||
require.Nil(t, appErr)
|
||||
thread, appErr := th.App.GetThreadForUser(th.BasicTeam.Id, threadMembership, false)
|
||||
thread, appErr := th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, int64(2), thread.UnreadMentions)
|
||||
require.Equal(t, int64(3), thread.UnreadReplies)
|
||||
|
||||
@@ -3029,7 +3029,7 @@ func getThreadForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
thread, err := c.App.GetThreadForUser(c.Params.TeamId, threadMembership, extended)
|
||||
thread, err := c.App.GetThreadForUser(threadMembership, extended)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -787,7 +787,7 @@ type AppIface interface {
|
||||
GetTeamsUnreadForUser(excludeTeamId string, userID string, includeCollapsedThreads bool) ([]*model.TeamUnread, *model.AppError)
|
||||
GetTeamsUsage() (*model.TeamsUsage, *model.AppError)
|
||||
GetTermsOfService(id string) (*model.TermsOfService, *model.AppError)
|
||||
GetThreadForUser(teamID string, threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, *model.AppError)
|
||||
GetThreadForUser(threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, *model.AppError)
|
||||
GetThreadMembershipForUser(userId, threadId string) (*model.ThreadMembership, *model.AppError)
|
||||
GetThreadMembershipsForUser(userID, teamID string) ([]*model.ThreadMembership, error)
|
||||
GetThreadsForUser(userID, teamID string, options model.GetUserThreadsOpts) (*model.Threads, *model.AppError)
|
||||
|
||||
@@ -2709,7 +2709,7 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(c request.CTX, postID st
|
||||
if mErr != nil {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(mErr)
|
||||
}
|
||||
thread, mErr := a.Srv().Store().Thread().GetThreadForUser(channel.TeamId, threadMembership, true)
|
||||
thread, mErr := a.Srv().Store().Thread().GetThreadForUser(threadMembership, true)
|
||||
if mErr != nil {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(mErr)
|
||||
}
|
||||
|
||||
@@ -2263,7 +2263,7 @@ func TestMarkChannelAsUnreadFromPostCollapsedThreadsTurnedOff(t *testing.T) {
|
||||
|
||||
threadMembership, err := th.App.GetThreadMembershipForUser(th.BasicUser.Id, rootPost1.Id)
|
||||
require.Nil(t, err)
|
||||
thread, err := th.App.GetThreadForUser(th.BasicTeam.Id, threadMembership, false)
|
||||
thread, err := th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, int64(2), thread.UnreadMentions)
|
||||
require.Equal(t, int64(3), thread.UnreadReplies)
|
||||
|
||||
@@ -596,7 +596,7 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea
|
||||
}
|
||||
threadMembership = tm
|
||||
}
|
||||
userThread, err := a.Srv().Store().Thread().GetThreadForUser(channel.TeamId, threadMembership, true)
|
||||
userThread, err := a.Srv().Store().Thread().GetThreadForUser(threadMembership, true)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "cannot get thread %q for user %q", post.RootId, uid)
|
||||
}
|
||||
|
||||
@@ -2769,7 +2769,7 @@ func TestReplyPostNotificationsWithCRT(t *testing.T) {
|
||||
|
||||
threadMembership, appErr := th.App.GetThreadMembershipForUser(u2.Id, rpost.Id)
|
||||
require.Nil(t, appErr)
|
||||
thread, appErr := th.App.GetThreadForUser(c1.TeamId, threadMembership, false)
|
||||
thread, appErr := th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, appErr)
|
||||
// Then: with notifications set to "all" we should
|
||||
// not see a mention badge
|
||||
|
||||
@@ -9799,7 +9799,7 @@ func (a *OpenTracingAppLayer) GetTermsOfService(id string) (*model.TermsOfServic
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetThreadForUser(teamID string, threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetThreadForUser(threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetThreadForUser")
|
||||
|
||||
@@ -9811,7 +9811,7 @@ func (a *OpenTracingAppLayer) GetThreadForUser(teamID string, threadMembership *
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetThreadForUser(teamID, threadMembership, extended)
|
||||
resultVar0, resultVar1 := a.app.GetThreadForUser(threadMembership, extended)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
|
||||
@@ -2327,7 +2327,7 @@ func TestFollowThreadSkipsParticipants(t *testing.T) {
|
||||
|
||||
threadMembership, err := th.App.GetThreadMembershipForUser(user.Id, p1.Id)
|
||||
require.Nil(t, err)
|
||||
thread, err := th.App.GetThreadForUser(th.BasicTeam.Id, threadMembership, false)
|
||||
thread, err := th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, thread.Participants, 1) // length should be 1, the original poster, since sysadmin was just mentioned but didn't post
|
||||
|
||||
@@ -2336,7 +2336,7 @@ func TestFollowThreadSkipsParticipants(t *testing.T) {
|
||||
|
||||
threadMembership, err = th.App.GetThreadMembershipForUser(user.Id, p1.Id)
|
||||
require.Nil(t, err)
|
||||
thread, err = th.App.GetThreadForUser(th.BasicTeam.Id, threadMembership, false)
|
||||
thread, err = th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, thread.Participants, 2) // length should be 2, the original poster and sysadmin, since sysadmin participated now
|
||||
|
||||
@@ -2345,7 +2345,7 @@ func TestFollowThreadSkipsParticipants(t *testing.T) {
|
||||
|
||||
threadMembership, err = th.App.GetThreadMembershipForUser(user2.Id, p1.Id)
|
||||
require.Nil(t, err)
|
||||
thread, err = th.App.GetThreadForUser(th.BasicTeam.Id, threadMembership, false)
|
||||
thread, err = th.App.GetThreadForUser(threadMembership, false)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, thread.Participants, 2) // length should be 2, since follow shouldn't update participant list, only user1 and sysadmin are participants
|
||||
for _, p := range thread.Participants {
|
||||
|
||||
@@ -2468,8 +2468,8 @@ func (a *App) GetThreadMembershipForUser(userId, threadId string) (*model.Thread
|
||||
return threadMembership, nil
|
||||
}
|
||||
|
||||
func (a *App) GetThreadForUser(teamID string, threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, *model.AppError) {
|
||||
thread, err := a.Srv().Store().Thread().GetThreadForUser(teamID, threadMembership, extended)
|
||||
func (a *App) GetThreadForUser(threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, *model.AppError) {
|
||||
thread, err := a.Srv().Store().Thread().GetThreadForUser(threadMembership, extended)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetThreadForUser", "app.user.get_threads_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
@@ -2551,7 +2551,7 @@ func (a *App) UpdateThreadFollowForUserFromChannelAdd(c request.CTX, userID, tea
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventThreadUpdated, teamID, "", userID, nil, "")
|
||||
userThread, err := a.Srv().Store().Thread().GetThreadForUser(teamID, tm, true)
|
||||
userThread, err := a.Srv().Store().Thread().GetThreadForUser(tm, true)
|
||||
|
||||
if err != nil {
|
||||
var errNotFound *store.ErrNotFound
|
||||
@@ -2633,7 +2633,7 @@ func (a *App) UpdateThreadReadForUser(c request.CTX, currentSessionId, userID, t
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
thread, err := a.GetThreadForUser(teamID, membership, false)
|
||||
thread, err := a.GetThreadForUser(membership, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -9890,7 +9890,7 @@ func (s *OpenTracingLayerThreadStore) GetThreadFollowers(threadID string, fetchO
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerThreadStore) GetThreadForUser(teamID string, threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error) {
|
||||
func (s *OpenTracingLayerThreadStore) GetThreadForUser(threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ThreadStore.GetThreadForUser")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -9899,7 +9899,7 @@ func (s *OpenTracingLayerThreadStore) GetThreadForUser(teamID string, threadMemb
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ThreadStore.GetThreadForUser(teamID, threadMembership, extended)
|
||||
result, err := s.ThreadStore.GetThreadForUser(threadMembership, extended)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
|
||||
@@ -11307,11 +11307,11 @@ func (s *RetryLayerThreadStore) GetThreadFollowers(threadID string, fetchOnlyAct
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerThreadStore) GetThreadForUser(teamID string, threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error) {
|
||||
func (s *RetryLayerThreadStore) GetThreadForUser(threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ThreadStore.GetThreadForUser(teamID, threadMembership, extended)
|
||||
result, err := s.ThreadStore.GetThreadForUser(threadMembership, extended)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -436,7 +436,7 @@ func (s *SqlThreadStore) GetThreadFollowers(threadID string, fetchOnlyActive boo
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func (s *SqlThreadStore) GetThreadForUser(teamId string, threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error) {
|
||||
func (s *SqlThreadStore) GetThreadForUser(threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error) {
|
||||
if !threadMembership.Following {
|
||||
return nil, nil // in case the thread is not followed anymore - return nil error to be interpreted as 404
|
||||
}
|
||||
@@ -450,11 +450,6 @@ func (s *SqlThreadStore) GetThreadForUser(teamId string, threadMembership *model
|
||||
sq.Eq{"Posts.DeleteAt": 0},
|
||||
})
|
||||
|
||||
fetchConditions := sq.And{
|
||||
sq.Or{sq.Eq{"Threads.ThreadTeamId": teamId}, sq.Eq{"Threads.ThreadTeamId": ""}},
|
||||
sq.Eq{"Threads.PostId": threadMembership.PostId},
|
||||
}
|
||||
|
||||
query := s.threadsAndPostsSelectQuery
|
||||
|
||||
for _, c := range postSliceColumns() {
|
||||
@@ -465,7 +460,7 @@ func (s *SqlThreadStore) GetThreadForUser(teamId string, threadMembership *model
|
||||
query = query.
|
||||
Column(sq.Alias(unreadRepliesQuery, "UnreadReplies")).
|
||||
LeftJoin("Posts ON Posts.Id = Threads.PostId").
|
||||
Where(fetchConditions)
|
||||
Where(sq.Eq{"Threads.PostId": threadMembership.PostId})
|
||||
|
||||
err := s.GetReplicaX().GetBuilder(&thread, query)
|
||||
if err != nil {
|
||||
|
||||
@@ -323,7 +323,7 @@ type ThreadStore interface {
|
||||
GetTotalThreads(userId, teamID string, opts model.GetUserThreadsOpts) (int64, error)
|
||||
GetTotalUnreadMentions(userId, teamID string, opts model.GetUserThreadsOpts) (int64, error)
|
||||
GetThreadsForUser(userId, teamID string, opts model.GetUserThreadsOpts) ([]*model.ThreadResponse, error)
|
||||
GetThreadForUser(teamID string, 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)
|
||||
GetPosts(threadID string, since int64) ([]*model.Post, error)
|
||||
|
||||
|
||||
@@ -188,13 +188,13 @@ func (_m *ThreadStore) GetThreadFollowers(threadID string, fetchOnlyActive bool)
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetThreadForUser provides a mock function with given fields: teamID, threadMembership, extended
|
||||
func (_m *ThreadStore) GetThreadForUser(teamID string, threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error) {
|
||||
ret := _m.Called(teamID, threadMembership, extended)
|
||||
// GetThreadForUser provides a mock function with given fields: threadMembership, extended
|
||||
func (_m *ThreadStore) GetThreadForUser(threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error) {
|
||||
ret := _m.Called(threadMembership, extended)
|
||||
|
||||
var r0 *model.ThreadResponse
|
||||
if rf, ok := ret.Get(0).(func(string, *model.ThreadMembership, bool) *model.ThreadResponse); ok {
|
||||
r0 = rf(teamID, threadMembership, extended)
|
||||
if rf, ok := ret.Get(0).(func(*model.ThreadMembership, bool) *model.ThreadResponse); ok {
|
||||
r0 = rf(threadMembership, extended)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.ThreadResponse)
|
||||
@@ -202,8 +202,8 @@ func (_m *ThreadStore) GetThreadForUser(teamID string, threadMembership *model.T
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, *model.ThreadMembership, bool) error); ok {
|
||||
r1 = rf(teamID, threadMembership, extended)
|
||||
if rf, ok := ret.Get(1).(func(*model.ThreadMembership, bool) error); ok {
|
||||
r1 = rf(threadMembership, extended)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
@@ -365,14 +365,14 @@ func testThreadStorePopulation(t *testing.T, ss store.Store) {
|
||||
}
|
||||
m, err := ss.Thread().MaintainMembership(newPosts[0].UserId, newPosts[0].Id, opts)
|
||||
require.NoError(t, err)
|
||||
th, err := ss.Thread().GetThreadForUser("", m, false)
|
||||
th, err := ss.Thread().GetThreadForUser(m, false)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(2), th.UnreadReplies)
|
||||
|
||||
m.LastViewed = newPosts[2].UpdateAt + 1
|
||||
_, err = ss.Thread().UpdateMembership(m)
|
||||
require.NoError(t, err)
|
||||
th, err = ss.Thread().GetThreadForUser("", m, false)
|
||||
th, err = ss.Thread().GetThreadForUser(m, false)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(0), th.UnreadReplies)
|
||||
|
||||
@@ -381,7 +381,7 @@ func testThreadStorePopulation(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Post().Update(editedPost, newPosts[2])
|
||||
require.NoError(t, err)
|
||||
|
||||
th, err = ss.Thread().GetThreadForUser("", m, false)
|
||||
th, err = ss.Thread().GetThreadForUser(m, false)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(0), th.UnreadReplies)
|
||||
})
|
||||
@@ -398,7 +398,7 @@ func testThreadStorePopulation(t *testing.T, ss store.Store) {
|
||||
m, err := ss.Thread().MaintainMembership("", newPosts[0].Id, opts)
|
||||
require.NoError(t, err)
|
||||
m.UserId = newPosts[0].UserId
|
||||
th, err := ss.Thread().GetThreadForUser("", m, true)
|
||||
th, err := ss.Thread().GetThreadForUser(m, true)
|
||||
require.NoError(t, err)
|
||||
for _, user := range th.Participants {
|
||||
require.NotNil(t, user)
|
||||
|
||||
@@ -8897,10 +8897,10 @@ func (s *TimerLayerThreadStore) GetThreadFollowers(threadID string, fetchOnlyAct
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerThreadStore) GetThreadForUser(teamID string, threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error) {
|
||||
func (s *TimerLayerThreadStore) GetThreadForUser(threadMembership *model.ThreadMembership, extended bool) (*model.ThreadResponse, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ThreadStore.GetThreadForUser(teamID, threadMembership, extended)
|
||||
result, err := s.ThreadStore.GetThreadForUser(threadMembership, extended)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user