Simplify thread_store/GetThreadForUser (#21588)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
534a9bcbf0
Коммит
b9d00a1f28
@@ -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