[MM-41998] Channel Info RHS: display number of files for a channel (#19822)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
@@ -1249,6 +1249,24 @@ func (s *OpenTracingLayerChannelStore) GetDeletedByName(team_id string, name str
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetFileCount(channelID string) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetFileCount")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ChannelStore.GetFileCount(channelID)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetForPost(postID string) (*model.Channel, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetForPost")
|
||||
|
||||
@@ -1402,6 +1402,27 @@ func (s *RetryLayerChannelStore) GetDeletedByName(team_id string, name string) (
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) GetFileCount(channelID string) (int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.GetFileCount(channelID)
|
||||
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 *RetryLayerChannelStore) GetForPost(postID string) (*model.Channel, error) {
|
||||
|
||||
tries := 0
|
||||
|
||||
@@ -2188,6 +2188,25 @@ func (s SqlChannelStore) GetMemberCountFromCache(channelId string) int64 {
|
||||
return count
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetFileCount(channelId string) (int64, error) {
|
||||
var count int64
|
||||
err := s.GetReplicaX().Get(&count, `
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
FileInfo
|
||||
LEFT JOIN Posts as P ON FileInfo.PostId=P.Id
|
||||
LEFT JOIN Channels as C on C.Id=P.ChannelId
|
||||
WHERE
|
||||
FileInfo.DeleteAt = 0
|
||||
AND C.Id = ?`, channelId)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to count files with channelId=%s", channelId)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, error) {
|
||||
var count int64
|
||||
|
||||
@@ -213,6 +213,7 @@ type ChannelStore interface {
|
||||
GetMemberForPost(postID string, userID string) (*model.ChannelMember, error)
|
||||
InvalidateMemberCount(channelID string)
|
||||
GetMemberCountFromCache(channelID string) int64
|
||||
GetFileCount(channelID string) (int64, error)
|
||||
GetMemberCount(channelID string, allowFromCache bool) (int64, error)
|
||||
GetMemberCountsByGroup(ctx context.Context, channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, error)
|
||||
InvalidatePinnedPostCount(channelID string)
|
||||
|
||||
@@ -881,6 +881,27 @@ func (_m *ChannelStore) GetDeletedByName(team_id string, name string) (*model.Ch
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetFileCount provides a mock function with given fields: channelID
|
||||
func (_m *ChannelStore) GetFileCount(channelID string) (int64, error) {
|
||||
ret := _m.Called(channelID)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
||||
r0 = rf(channelID)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(channelID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetForPost provides a mock function with given fields: postID
|
||||
func (_m *ChannelStore) GetForPost(postID string) (*model.Channel, error) {
|
||||
ret := _m.Called(postID)
|
||||
|
||||
@@ -1157,6 +1157,22 @@ func (s *TimerLayerChannelStore) GetDeletedByName(team_id string, name string) (
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetFileCount(channelID string) (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.ChannelStore.GetFileCount(channelID)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.GetFileCount", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetForPost(postID string) (*model.Channel, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user