[MM-22133] Allow exporting and importing archived channels (#23724)
Этот коммит содержится в:
@@ -1106,6 +1106,24 @@ func (s *OpenTracingLayerChannelStore) GetByNames(team_id string, names []string
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetByNamesIncludeDeleted(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetByNamesIncludeDeleted")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ChannelStore.GetByNamesIncludeDeleted(team_id, names, allowFromCache)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetChannelCounts(teamID string, userID string) (*model.ChannelCounts, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetChannelCounts")
|
||||
@@ -1124,7 +1142,7 @@ func (s *OpenTracingLayerChannelStore) GetChannelCounts(teamID string, userID st
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetChannelMembersForExport(userID string, teamID string) ([]*model.ChannelMemberForExport, error) {
|
||||
func (s *OpenTracingLayerChannelStore) GetChannelMembersForExport(userID string, teamID string, includeArchivedChannel bool) ([]*model.ChannelMemberForExport, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetChannelMembersForExport")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -1133,7 +1151,7 @@ func (s *OpenTracingLayerChannelStore) GetChannelMembersForExport(userID string,
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.ChannelStore.GetChannelMembersForExport(userID, teamID)
|
||||
result, err := s.ChannelStore.GetChannelMembersForExport(userID, teamID, includeArchivedChannel)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
@@ -6097,7 +6115,7 @@ func (s *OpenTracingLayerPostStore) GetOldestEntityCreationTime() (int64, error)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerPostStore) GetParentsForExportAfter(limit int, afterID string) ([]*model.PostForExport, error) {
|
||||
func (s *OpenTracingLayerPostStore) GetParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.PostForExport, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetParentsForExportAfter")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -6106,7 +6124,7 @@ func (s *OpenTracingLayerPostStore) GetParentsForExportAfter(limit int, afterID
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.PostStore.GetParentsForExportAfter(limit, afterID)
|
||||
result, err := s.PostStore.GetParentsForExportAfter(limit, afterID, includeArchivedChannels)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
|
||||
@@ -1216,6 +1216,27 @@ func (s *RetryLayerChannelStore) GetByNames(team_id string, names []string, allo
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) GetByNamesIncludeDeleted(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.GetByNamesIncludeDeleted(team_id, names, allowFromCache)
|
||||
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) GetChannelCounts(teamID string, userID string) (*model.ChannelCounts, error) {
|
||||
|
||||
tries := 0
|
||||
@@ -1237,11 +1258,11 @@ func (s *RetryLayerChannelStore) GetChannelCounts(teamID string, userID string)
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerChannelStore) GetChannelMembersForExport(userID string, teamID string) ([]*model.ChannelMemberForExport, error) {
|
||||
func (s *RetryLayerChannelStore) GetChannelMembersForExport(userID string, teamID string, includeArchivedChannel bool) ([]*model.ChannelMemberForExport, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.ChannelStore.GetChannelMembersForExport(userID, teamID)
|
||||
result, err := s.ChannelStore.GetChannelMembersForExport(userID, teamID, includeArchivedChannel)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
@@ -6892,11 +6913,11 @@ func (s *RetryLayerPostStore) GetOldestEntityCreationTime() (int64, error) {
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerPostStore) GetParentsForExportAfter(limit int, afterID string) ([]*model.PostForExport, error) {
|
||||
func (s *RetryLayerPostStore) GetParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.PostForExport, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.PostStore.GetParentsForExportAfter(limit, afterID)
|
||||
result, err := s.PostStore.GetParentsForExportAfter(limit, afterID, includeArchivedChannels)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -1468,7 +1468,15 @@ func (s SqlChannelStore) GetByName(teamId string, name string, allowFromCache bo
|
||||
return s.getByName(teamId, name, false, allowFromCache)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetByNamesIncludeDeleted(teamId string, names []string, allowFromCache bool) ([]*model.Channel, error) {
|
||||
return s.getByNames(teamId, names, allowFromCache, true)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCache bool) ([]*model.Channel, error) {
|
||||
return s.getByNames(teamId, names, allowFromCache, false)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) getByNames(teamId string, names []string, allowFromCache, includeArchivedChannels bool) ([]*model.Channel, error) {
|
||||
var channels []*model.Channel
|
||||
|
||||
if allowFromCache {
|
||||
@@ -1481,7 +1489,9 @@ func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCach
|
||||
visited[name] = struct{}{}
|
||||
var cacheItem *model.Channel
|
||||
if err := channelByNameCache.Get(teamId+name, &cacheItem); err == nil {
|
||||
channels = append(channels, cacheItem)
|
||||
if includeArchivedChannels || cacheItem.DeleteAt == 0 {
|
||||
channels = append(channels, cacheItem)
|
||||
}
|
||||
} else {
|
||||
misses = append(misses, name)
|
||||
}
|
||||
@@ -1490,15 +1500,17 @@ func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCach
|
||||
}
|
||||
|
||||
if len(names) > 0 {
|
||||
cond := sq.And{
|
||||
sq.Eq{"Name": names},
|
||||
}
|
||||
if !includeArchivedChannels {
|
||||
cond = append(cond, sq.Eq{"DeleteAt": 0})
|
||||
}
|
||||
|
||||
builder := s.getQueryBuilder().
|
||||
Select("*").
|
||||
From("Channels").
|
||||
Where(
|
||||
sq.And{
|
||||
sq.Eq{"Name": names},
|
||||
sq.Eq{"DeleteAt": 0},
|
||||
},
|
||||
)
|
||||
Where(cond)
|
||||
|
||||
if teamId != "" {
|
||||
builder = builder.Where(sq.Eq{"TeamId": teamId})
|
||||
@@ -4191,34 +4203,36 @@ func (s SqlChannelStore) GetAllChannelsForExportAfter(limit int, afterId string)
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetChannelMembersForExport(userId string, teamId string) ([]*model.ChannelMemberForExport, error) {
|
||||
func (s SqlChannelStore) GetChannelMembersForExport(userId string, teamId string, includeArchivedChannel bool) ([]*model.ChannelMemberForExport, error) {
|
||||
members := []*model.ChannelMemberForExport{}
|
||||
err := s.GetReplicaX().Select(&members, `
|
||||
SELECT
|
||||
ChannelMembers.ChannelId,
|
||||
ChannelMembers.UserId,
|
||||
ChannelMembers.Roles,
|
||||
ChannelMembers.LastViewedAt,
|
||||
ChannelMembers.MsgCount,
|
||||
ChannelMembers.MentionCount,
|
||||
ChannelMembers.MentionCountRoot,
|
||||
COALESCE(ChannelMembers.UrgentMentionCount, 0) AS UrgentMentionCount,
|
||||
ChannelMembers.MsgCountRoot,
|
||||
ChannelMembers.NotifyProps,
|
||||
ChannelMembers.LastUpdateAt,
|
||||
ChannelMembers.SchemeUser,
|
||||
ChannelMembers.SchemeAdmin,
|
||||
(ChannelMembers.SchemeGuest IS NOT NULL AND ChannelMembers.SchemeGuest) as SchemeGuest,
|
||||
Channels.Name as ChannelName
|
||||
FROM
|
||||
ChannelMembers
|
||||
INNER JOIN
|
||||
Channels ON ChannelMembers.ChannelId = Channels.Id
|
||||
WHERE
|
||||
ChannelMembers.UserId = ?
|
||||
AND Channels.TeamId = ?
|
||||
AND Channels.DeleteAt = 0`,
|
||||
userId, teamId)
|
||||
q := `
|
||||
SELECT
|
||||
ChannelMembers.ChannelId,
|
||||
ChannelMembers.UserId,
|
||||
ChannelMembers.Roles,
|
||||
ChannelMembers.LastViewedAt,
|
||||
ChannelMembers.MsgCount,
|
||||
ChannelMembers.MentionCount,
|
||||
ChannelMembers.MentionCountRoot,
|
||||
COALESCE(ChannelMembers.UrgentMentionCount, 0) AS UrgentMentionCount,
|
||||
ChannelMembers.MsgCountRoot,
|
||||
ChannelMembers.NotifyProps,
|
||||
ChannelMembers.LastUpdateAt,
|
||||
ChannelMembers.SchemeUser,
|
||||
ChannelMembers.SchemeAdmin,
|
||||
(ChannelMembers.SchemeGuest IS NOT NULL AND ChannelMembers.SchemeGuest) as SchemeGuest,
|
||||
Channels.Name as ChannelName
|
||||
FROM
|
||||
ChannelMembers
|
||||
INNER JOIN
|
||||
Channels ON ChannelMembers.ChannelId = Channels.Id
|
||||
WHERE
|
||||
ChannelMembers.UserId = ?
|
||||
AND Channels.TeamId = ?`
|
||||
if !includeArchivedChannel {
|
||||
q += " AND Channels.DeleteAt = 0"
|
||||
}
|
||||
err := s.GetReplicaX().Select(&members, q, userId, teamId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Channels for export")
|
||||
}
|
||||
|
||||
@@ -2556,7 +2556,7 @@ func (s *SqlPostStore) GetMaxPostSize() int {
|
||||
return s.maxPostSizeCached
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetParentsForExportAfter(limit int, afterId string) ([]*model.PostForExport, error) {
|
||||
func (s *SqlPostStore) GetParentsForExportAfter(limit int, afterId string, includeArchivedChannel bool) ([]*model.PostForExport, error) {
|
||||
for {
|
||||
rootIds := []string{}
|
||||
err := s.GetReplicaX().Select(&rootIds,
|
||||
@@ -2580,16 +2580,20 @@ func (s *SqlPostStore) GetParentsForExportAfter(limit int, afterId string) ([]*m
|
||||
return postsForExport, nil
|
||||
}
|
||||
|
||||
excludeDeletedCond := sq.And{
|
||||
sq.Eq{"Teams.DeleteAt": 0},
|
||||
}
|
||||
if !includeArchivedChannel {
|
||||
excludeDeletedCond = append(excludeDeletedCond, sq.Eq{"Channels.DeleteAt": 0})
|
||||
}
|
||||
|
||||
builder := s.getQueryBuilder().
|
||||
Select("p1.*, Users.Username as Username, Teams.Name as TeamName, Channels.Name as ChannelName").
|
||||
FromSelect(sq.Select("*").From("Posts").Where(sq.Eq{"Posts.Id": rootIds}), "p1").
|
||||
InnerJoin("Channels ON p1.ChannelId = Channels.Id").
|
||||
InnerJoin("Teams ON Channels.TeamId = Teams.Id").
|
||||
InnerJoin("Users ON p1.UserId = Users.Id").
|
||||
Where(sq.And{
|
||||
sq.Eq{"Channels.DeleteAt": 0},
|
||||
sq.Eq{"Teams.DeleteAt": 0},
|
||||
}).
|
||||
Where(excludeDeletedCond).
|
||||
OrderBy("p1.Id")
|
||||
|
||||
query, args, err := builder.ToSql()
|
||||
|
||||
@@ -192,6 +192,7 @@ type ChannelStore interface {
|
||||
GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, error)
|
||||
GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error)
|
||||
GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, error)
|
||||
GetByNamesIncludeDeleted(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error)
|
||||
GetDeletedByName(team_id string, name string) (*model.Channel, error)
|
||||
GetDeleted(team_id string, offset int, limit int, userID string) (model.ChannelList, error)
|
||||
GetChannels(teamID, userID string, opts *model.ChannelSearchOpts) (model.ChannelList, error)
|
||||
@@ -285,7 +286,7 @@ type ChannelStore interface {
|
||||
DeleteSidebarCategory(categoryID string) error
|
||||
GetAllChannelsForExportAfter(limit int, afterID string) ([]*model.ChannelForExport, error)
|
||||
GetAllDirectChannelsForExportAfter(limit int, afterID string) ([]*model.DirectChannelForExport, error)
|
||||
GetChannelMembersForExport(userID string, teamID string) ([]*model.ChannelMemberForExport, error)
|
||||
GetChannelMembersForExport(userID string, teamID string, includeArchivedChannel bool) ([]*model.ChannelMemberForExport, error)
|
||||
RemoveAllDeactivatedMembers(channelID string) error
|
||||
GetChannelsBatchForIndexing(startTime int64, startChannelID string, limit int) ([]*model.Channel, error)
|
||||
UserBelongsToChannels(userID string, channelIds []string) (bool, error)
|
||||
@@ -379,7 +380,7 @@ type PostStore interface {
|
||||
PermanentDeleteBatch(endTime int64, limit int64) (int64, error)
|
||||
GetOldest() (*model.Post, error)
|
||||
GetMaxPostSize() int
|
||||
GetParentsForExportAfter(limit int, afterID string) ([]*model.PostForExport, error)
|
||||
GetParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.PostForExport, error)
|
||||
GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error)
|
||||
GetDirectPostParentsForExportAfter(limit int, afterID string) ([]*model.DirectPostForExport, error)
|
||||
SearchPostsForUser(paramsList []*model.SearchParams, userID, teamID string, page, perPage int) (*model.PostSearchResults, error)
|
||||
|
||||
@@ -81,6 +81,7 @@ func TestChannelStore(t *testing.T, ss store.Store, s SqlStore) {
|
||||
t.Run("Delete", func(t *testing.T) { testChannelStoreDelete(t, ss) })
|
||||
t.Run("GetByName", func(t *testing.T) { testChannelStoreGetByName(t, ss) })
|
||||
t.Run("GetByNames", func(t *testing.T) { testChannelStoreGetByNames(t, ss) })
|
||||
t.Run("GetByNamesIncludeDeleted", func(t *testing.T) { testChannelStoreGetByNamesIncludeDeleted(t, ss) })
|
||||
t.Run("GetDeletedByName", func(t *testing.T) { testChannelStoreGetDeletedByName(t, ss) })
|
||||
t.Run("GetDeleted", func(t *testing.T) { testChannelStoreGetDeleted(t, ss) })
|
||||
t.Run("ChannelMemberStore", func(t *testing.T) { testChannelMemberStore(t, ss) })
|
||||
@@ -859,6 +860,17 @@ func testChannelStoreGetByNames(t *testing.T, ss store.Store) {
|
||||
_, nErr = ss.Channel().Save(&o2, -1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
o3 := model.Channel{
|
||||
TeamId: o1.TeamId,
|
||||
DisplayName: "Name",
|
||||
Name: NewTestId(),
|
||||
Type: model.ChannelTypeOpen,
|
||||
}
|
||||
_, nErr = ss.Channel().Save(&o3, -1)
|
||||
require.NoError(t, nErr)
|
||||
nErr = ss.Channel().Delete(o3.Id, model.GetMillis())
|
||||
require.NoError(t, nErr)
|
||||
|
||||
for index, tc := range []struct {
|
||||
TeamId string
|
||||
Names []string
|
||||
@@ -895,6 +907,53 @@ func testChannelStoreGetByNames(t *testing.T, ss store.Store) {
|
||||
assert.Empty(t, channels)
|
||||
}
|
||||
|
||||
func testChannelStoreGetByNamesIncludeDeleted(t *testing.T, ss store.Store) {
|
||||
o1 := model.Channel{
|
||||
TeamId: model.NewId(),
|
||||
DisplayName: "Name",
|
||||
Name: NewTestId(),
|
||||
Type: model.ChannelTypeOpen,
|
||||
}
|
||||
_, nErr := ss.Channel().Save(&o1, -1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
o2 := model.Channel{
|
||||
TeamId: o1.TeamId,
|
||||
DisplayName: "Name",
|
||||
Name: NewTestId(),
|
||||
Type: model.ChannelTypeOpen,
|
||||
}
|
||||
_, nErr = ss.Channel().Save(&o2, -1)
|
||||
require.NoError(t, nErr)
|
||||
nErr = ss.Channel().Delete(o2.Id, model.GetMillis())
|
||||
require.NoError(t, nErr, "channel should have been deleted")
|
||||
|
||||
for index, tc := range []struct {
|
||||
TeamId string
|
||||
Names []string
|
||||
ExpectedIds []string
|
||||
}{
|
||||
{o1.TeamId, []string{o1.Name}, []string{o1.Id}},
|
||||
{o1.TeamId, []string{o1.Name, o2.Name}, []string{o1.Id, o2.Id}},
|
||||
{o1.TeamId, nil, nil},
|
||||
{o1.TeamId, []string{"foo"}, nil},
|
||||
{o1.TeamId, []string{o1.Name, "foo", o2.Name, o2.Name}, []string{o1.Id, o2.Id}},
|
||||
{"", []string{o1.Name, "foo", o2.Name, o2.Name}, []string{o1.Id, o2.Id}},
|
||||
{"asd", []string{o1.Name, "foo", o2.Name, o2.Name}, nil},
|
||||
} {
|
||||
var channels []*model.Channel
|
||||
channels, err := ss.Channel().GetByNamesIncludeDeleted(tc.TeamId, tc.Names, true)
|
||||
require.NoError(t, err)
|
||||
var ids []string
|
||||
for _, channel := range channels {
|
||||
ids = append(ids, channel.Id)
|
||||
}
|
||||
sort.Strings(ids)
|
||||
sort.Strings(tc.ExpectedIds)
|
||||
assert.Equal(t, tc.ExpectedIds, ids, "tc %v", index)
|
||||
}
|
||||
}
|
||||
|
||||
func testChannelStoreGetDeletedByName(t *testing.T, ss store.Store) {
|
||||
o1 := &model.Channel{}
|
||||
o1.TeamId = model.NewId()
|
||||
@@ -7648,7 +7707,7 @@ func testChannelStoreGetChannelMembersForExport(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Channel().SaveMember(&m2)
|
||||
require.NoError(t, err)
|
||||
|
||||
d1, err := ss.Channel().GetChannelMembersForExport(u1.Id, t1.Id)
|
||||
d1, err := ss.Channel().GetChannelMembersForExport(u1.Id, t1.Id, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Len(t, d1, 1)
|
||||
|
||||
@@ -674,6 +674,32 @@ func (_m *ChannelStore) GetByNames(team_id string, names []string, allowFromCach
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetByNamesIncludeDeleted provides a mock function with given fields: team_id, names, allowFromCache
|
||||
func (_m *ChannelStore) GetByNamesIncludeDeleted(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error) {
|
||||
ret := _m.Called(team_id, names, allowFromCache)
|
||||
|
||||
var r0 []*model.Channel
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, []string, bool) ([]*model.Channel, error)); ok {
|
||||
return rf(team_id, names, allowFromCache)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, []string, bool) []*model.Channel); ok {
|
||||
r0 = rf(team_id, names, allowFromCache)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Channel)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, []string, bool) error); ok {
|
||||
r1 = rf(team_id, names, allowFromCache)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetChannelCounts provides a mock function with given fields: teamID, userID
|
||||
func (_m *ChannelStore) GetChannelCounts(teamID string, userID string) (*model.ChannelCounts, error) {
|
||||
ret := _m.Called(teamID, userID)
|
||||
@@ -700,25 +726,25 @@ func (_m *ChannelStore) GetChannelCounts(teamID string, userID string) (*model.C
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetChannelMembersForExport provides a mock function with given fields: userID, teamID
|
||||
func (_m *ChannelStore) GetChannelMembersForExport(userID string, teamID string) ([]*model.ChannelMemberForExport, error) {
|
||||
ret := _m.Called(userID, teamID)
|
||||
// GetChannelMembersForExport provides a mock function with given fields: userID, teamID, includeArchivedChannel
|
||||
func (_m *ChannelStore) GetChannelMembersForExport(userID string, teamID string, includeArchivedChannel bool) ([]*model.ChannelMemberForExport, error) {
|
||||
ret := _m.Called(userID, teamID, includeArchivedChannel)
|
||||
|
||||
var r0 []*model.ChannelMemberForExport
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, string) ([]*model.ChannelMemberForExport, error)); ok {
|
||||
return rf(userID, teamID)
|
||||
if rf, ok := ret.Get(0).(func(string, string, bool) ([]*model.ChannelMemberForExport, error)); ok {
|
||||
return rf(userID, teamID, includeArchivedChannel)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, string) []*model.ChannelMemberForExport); ok {
|
||||
r0 = rf(userID, teamID)
|
||||
if rf, ok := ret.Get(0).(func(string, string, bool) []*model.ChannelMemberForExport); ok {
|
||||
r0 = rf(userID, teamID, includeArchivedChannel)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.ChannelMemberForExport)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, string) error); ok {
|
||||
r1 = rf(userID, teamID)
|
||||
if rf, ok := ret.Get(1).(func(string, string, bool) error); ok {
|
||||
r1 = rf(userID, teamID, includeArchivedChannel)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
@@ -395,25 +395,25 @@ func (_m *PostStore) GetOldestEntityCreationTime() (int64, error) {
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetParentsForExportAfter provides a mock function with given fields: limit, afterID
|
||||
func (_m *PostStore) GetParentsForExportAfter(limit int, afterID string) ([]*model.PostForExport, error) {
|
||||
ret := _m.Called(limit, afterID)
|
||||
// GetParentsForExportAfter provides a mock function with given fields: limit, afterID, includeArchivedChannels
|
||||
func (_m *PostStore) GetParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.PostForExport, error) {
|
||||
ret := _m.Called(limit, afterID, includeArchivedChannels)
|
||||
|
||||
var r0 []*model.PostForExport
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(int, string) ([]*model.PostForExport, error)); ok {
|
||||
return rf(limit, afterID)
|
||||
if rf, ok := ret.Get(0).(func(int, string, bool) ([]*model.PostForExport, error)); ok {
|
||||
return rf(limit, afterID, includeArchivedChannels)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(int, string) []*model.PostForExport); ok {
|
||||
r0 = rf(limit, afterID)
|
||||
if rf, ok := ret.Get(0).(func(int, string, bool) []*model.PostForExport); ok {
|
||||
r0 = rf(limit, afterID, includeArchivedChannels)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.PostForExport)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(int, string) error); ok {
|
||||
r1 = rf(limit, afterID)
|
||||
if rf, ok := ret.Get(1).(func(int, string, bool) error); ok {
|
||||
r1 = rf(limit, afterID, includeArchivedChannels)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
@@ -4154,6 +4154,14 @@ func testPostStoreGetParentsForExportAfter(t *testing.T, ss store.Store) {
|
||||
_, nErr := ss.Channel().Save(&c1, -1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
c2 := model.Channel{}
|
||||
c2.TeamId = t1.Id
|
||||
c2.DisplayName = "Channel2"
|
||||
c2.Name = NewTestId()
|
||||
c2.Type = model.ChannelTypeOpen
|
||||
_, nErr = ss.Channel().Save(&c2, -1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
u1 := model.User{}
|
||||
u1.Username = model.NewId()
|
||||
u1.Email = MakeEmail()
|
||||
@@ -4169,21 +4177,56 @@ func testPostStoreGetParentsForExportAfter(t *testing.T, ss store.Store) {
|
||||
p1, nErr = ss.Post().Save(p1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
posts, err := ss.Post().GetParentsForExportAfter(10000, strings.Repeat("0", 26))
|
||||
assert.NoError(t, err)
|
||||
p2 := &model.Post{}
|
||||
p2.ChannelId = c2.Id
|
||||
p2.UserId = u1.Id
|
||||
p2.Message = NewTestId()
|
||||
p2.CreateAt = 1000
|
||||
p2, nErr = ss.Post().Save(p2)
|
||||
require.NoError(t, nErr)
|
||||
nErr = ss.Channel().Delete(c2.Id, model.GetMillis())
|
||||
require.NoError(t, nErr)
|
||||
|
||||
found := false
|
||||
for _, p := range posts {
|
||||
if p.Id == p1.Id {
|
||||
found = true
|
||||
assert.Equal(t, p.Id, p1.Id)
|
||||
assert.Equal(t, p.Message, p1.Message)
|
||||
assert.Equal(t, p.Username, u1.Username)
|
||||
assert.Equal(t, p.TeamName, t1.Name)
|
||||
assert.Equal(t, p.ChannelName, c1.Name)
|
||||
t.Run("without archived channels", func(t *testing.T) {
|
||||
posts, err := ss.Post().GetParentsForExportAfter(10000, strings.Repeat("0", 26), false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
found := false
|
||||
foundArchived := false
|
||||
for _, p := range posts {
|
||||
if p.Id == p1.Id {
|
||||
found = true
|
||||
assert.Equal(t, p.Id, p1.Id)
|
||||
assert.Equal(t, p.Message, p1.Message)
|
||||
assert.Equal(t, p.Username, u1.Username)
|
||||
assert.Equal(t, p.TeamName, t1.Name)
|
||||
assert.Equal(t, p.ChannelName, c1.Name)
|
||||
}
|
||||
if p.Id == p2.Id {
|
||||
foundArchived = true
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.True(t, found)
|
||||
assert.True(t, found)
|
||||
assert.False(t, foundArchived, "posts from archived channel should not be returned")
|
||||
})
|
||||
|
||||
t.Run("with archived channels", func(t *testing.T) {
|
||||
posts, err := ss.Post().GetParentsForExportAfter(10000, strings.Repeat("0", 26), true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
found := false
|
||||
for _, p := range posts {
|
||||
if p.Id == p2.Id {
|
||||
found = true
|
||||
assert.Equal(t, p.Id, p2.Id)
|
||||
assert.Equal(t, p.Message, p2.Message)
|
||||
assert.Equal(t, p.Username, u1.Username)
|
||||
assert.Equal(t, p.TeamName, t1.Name)
|
||||
assert.Equal(t, p.ChannelName, c2.Name)
|
||||
}
|
||||
}
|
||||
assert.True(t, found)
|
||||
})
|
||||
}
|
||||
|
||||
func testPostStoreGetRepliesForExport(t *testing.T, ss store.Store) {
|
||||
|
||||
@@ -1040,6 +1040,22 @@ func (s *TimerLayerChannelStore) GetByNames(team_id string, names []string, allo
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetByNamesIncludeDeleted(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.GetByNamesIncludeDeleted(team_id, names, allowFromCache)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.GetByNamesIncludeDeleted", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetChannelCounts(teamID string, userID string) (*model.ChannelCounts, error) {
|
||||
start := time.Now()
|
||||
|
||||
@@ -1056,10 +1072,10 @@ func (s *TimerLayerChannelStore) GetChannelCounts(teamID string, userID string)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetChannelMembersForExport(userID string, teamID string) ([]*model.ChannelMemberForExport, error) {
|
||||
func (s *TimerLayerChannelStore) GetChannelMembersForExport(userID string, teamID string, includeArchivedChannel bool) ([]*model.ChannelMemberForExport, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.ChannelStore.GetChannelMembersForExport(userID, teamID)
|
||||
result, err := s.ChannelStore.GetChannelMembersForExport(userID, teamID, includeArchivedChannel)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -5525,10 +5541,10 @@ func (s *TimerLayerPostStore) GetOldestEntityCreationTime() (int64, error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerPostStore) GetParentsForExportAfter(limit int, afterID string) ([]*model.PostForExport, error) {
|
||||
func (s *TimerLayerPostStore) GetParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.PostForExport, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.PostStore.GetParentsForExportAfter(limit, afterID)
|
||||
result, err := s.PostStore.GetParentsForExportAfter(limit, afterID, includeArchivedChannels)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user