Migrate Channel.MigrateChannelMembers to Sync by default (#11277)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
de8a60225b
Коммит
bd3f72254d
@@ -87,16 +87,15 @@ func (worker *Worker) runAdvancedPermissionsPhase2Migration(lastDone string) (bo
|
|||||||
}
|
}
|
||||||
} else if progress.CurrentTable == "ChannelMembers" {
|
} else if progress.CurrentTable == "ChannelMembers" {
|
||||||
// Run a ChannelMembers migration batch.
|
// Run a ChannelMembers migration batch.
|
||||||
if result := <-worker.app.Srv.Store.Channel().MigrateChannelMembers(progress.LastChannelId, progress.LastUserId); result.Err != nil {
|
if data, err := worker.app.Srv.Store.Channel().MigrateChannelMembers(progress.LastChannelId, progress.LastUserId); err != nil {
|
||||||
return false, progress.ToJson(), result.Err
|
return false, progress.ToJson(), err
|
||||||
} else {
|
} else {
|
||||||
if result.Data == nil {
|
if data == nil {
|
||||||
// We haven't progressed. That means we've reached the end of this final stage of the migration.
|
// We haven't progressed. That means we've reached the end of this final stage of the migration.
|
||||||
|
|
||||||
return true, progress.ToJson(), nil
|
return true, progress.ToJson(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
data := result.Data.(map[string]string)
|
|
||||||
progress.LastChannelId = data["ChannelId"]
|
progress.LastChannelId = data["ChannelId"]
|
||||||
progress.LastUserId = data["UserId"]
|
progress.LastUserId = data["UserId"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2292,26 +2292,23 @@ func (s SqlChannelStore) GetChannelsByScheme(schemeId string, offset int, limit
|
|||||||
// in batches as a single transaction per batch to ensure consistency but to also minimise execution time to avoid
|
// in batches as a single transaction per batch to ensure consistency but to also minimise execution time to avoid
|
||||||
// causing unnecessary table locks. **THIS FUNCTION SHOULD NOT BE USED FOR ANY OTHER PURPOSE.** Executing this function
|
// causing unnecessary table locks. **THIS FUNCTION SHOULD NOT BE USED FOR ANY OTHER PURPOSE.** Executing this function
|
||||||
// *after* the new Schemes functionality has been used on an installation will have unintended consequences.
|
// *after* the new Schemes functionality has been used on an installation will have unintended consequences.
|
||||||
func (s SqlChannelStore) MigrateChannelMembers(fromChannelId string, fromUserId string) store.StoreChannel {
|
func (s SqlChannelStore) MigrateChannelMembers(fromChannelId string, fromUserId string) (map[string]string, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
var transaction *gorp.Transaction
|
var transaction *gorp.Transaction
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if transaction, err = s.GetMaster().Begin(); err != nil {
|
if transaction, err = s.GetMaster().Begin(); err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.MigrateChannelMembers", "store.sql_channel.migrate_channel_members.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlChannelStore.MigrateChannelMembers", "store.sql_channel.migrate_channel_members.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer finalizeTransaction(transaction)
|
defer finalizeTransaction(transaction)
|
||||||
|
|
||||||
var channelMembers []channelMember
|
var channelMembers []channelMember
|
||||||
if _, err := transaction.Select(&channelMembers, "SELECT * from ChannelMembers WHERE (ChannelId, UserId) > (:FromChannelId, :FromUserId) ORDER BY ChannelId, UserId LIMIT 100", map[string]interface{}{"FromChannelId": fromChannelId, "FromUserId": fromUserId}); err != nil {
|
if _, err := transaction.Select(&channelMembers, "SELECT * from ChannelMembers WHERE (ChannelId, UserId) > (:FromChannelId, :FromUserId) ORDER BY ChannelId, UserId LIMIT 100", map[string]interface{}{"FromChannelId": fromChannelId, "FromUserId": fromUserId}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.MigrateChannelMembers", "store.sql_channel.migrate_channel_members.select.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlChannelStore.MigrateChannelMembers", "store.sql_channel.migrate_channel_members.select.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(channelMembers) == 0 {
|
if len(channelMembers) == 0 {
|
||||||
// No more channel members in query result means that the migration has finished.
|
// No more channel members in query result means that the migration has finished.
|
||||||
return
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, member := range channelMembers {
|
for _, member := range channelMembers {
|
||||||
@@ -2340,22 +2337,19 @@ func (s SqlChannelStore) MigrateChannelMembers(fromChannelId string, fromUserId
|
|||||||
member.Roles = strings.Join(newRoles, " ")
|
member.Roles = strings.Join(newRoles, " ")
|
||||||
|
|
||||||
if _, err := transaction.Update(&member); err != nil {
|
if _, err := transaction.Update(&member); err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.MigrateChannelMembers", "store.sql_channel.migrate_channel_members.update.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlChannelStore.MigrateChannelMembers", "store.sql_channel.migrate_channel_members.update.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := transaction.Commit(); err != nil {
|
if err := transaction.Commit(); err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.MigrateChannelMembers", "store.sql_channel.migrate_channel_members.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlChannelStore.MigrateChannelMembers", "store.sql_channel.migrate_channel_members.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data := make(map[string]string)
|
data := make(map[string]string)
|
||||||
data["ChannelId"] = channelMembers[len(channelMembers)-1].ChannelId
|
data["ChannelId"] = channelMembers[len(channelMembers)-1].ChannelId
|
||||||
data["UserId"] = channelMembers[len(channelMembers)-1].UserId
|
data["UserId"] = channelMembers[len(channelMembers)-1].UserId
|
||||||
result.Data = data
|
return data, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) ResetAllChannelSchemes() store.StoreChannel {
|
func (s SqlChannelStore) ResetAllChannelSchemes() store.StoreChannel {
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ type ChannelStore interface {
|
|||||||
GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError)
|
GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError)
|
||||||
ClearCaches()
|
ClearCaches()
|
||||||
GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel
|
GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel
|
||||||
MigrateChannelMembers(fromChannelId string, fromUserId string) StoreChannel
|
MigrateChannelMembers(fromChannelId string, fromUserId string) (map[string]string, *model.AppError)
|
||||||
ResetAllChannelSchemes() StoreChannel
|
ResetAllChannelSchemes() StoreChannel
|
||||||
ClearAllCustomRoleAssignments() *model.AppError
|
ClearAllCustomRoleAssignments() *model.AppError
|
||||||
MigratePublicChannels() error
|
MigratePublicChannels() error
|
||||||
|
|||||||
@@ -2966,12 +2966,11 @@ func testChannelStoreMigrateChannelMembers(t *testing.T, ss store.Store) {
|
|||||||
lastDoneUserId := strings.Repeat("0", 26)
|
lastDoneUserId := strings.Repeat("0", 26)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
res := <-ss.Channel().MigrateChannelMembers(lastDoneChannelId, lastDoneUserId)
|
data, err := ss.Channel().MigrateChannelMembers(lastDoneChannelId, lastDoneUserId)
|
||||||
if assert.Nil(t, res.Err) {
|
if assert.Nil(t, err) {
|
||||||
if res.Data == nil {
|
if data == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
data := res.Data.(map[string]string)
|
|
||||||
lastDoneChannelId = data["ChannelId"]
|
lastDoneChannelId = data["ChannelId"]
|
||||||
lastDoneUserId = data["UserId"]
|
lastDoneUserId = data["UserId"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -983,19 +983,28 @@ func (_m *ChannelStore) IsUserInChannelUseCache(userId string, channelId string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MigrateChannelMembers provides a mock function with given fields: fromChannelId, fromUserId
|
// MigrateChannelMembers provides a mock function with given fields: fromChannelId, fromUserId
|
||||||
func (_m *ChannelStore) MigrateChannelMembers(fromChannelId string, fromUserId string) store.StoreChannel {
|
func (_m *ChannelStore) MigrateChannelMembers(fromChannelId string, fromUserId string) (map[string]string, *model.AppError) {
|
||||||
ret := _m.Called(fromChannelId, fromUserId)
|
ret := _m.Called(fromChannelId, fromUserId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 map[string]string
|
||||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string) map[string]string); ok {
|
||||||
r0 = rf(fromChannelId, fromUserId)
|
r0 = rf(fromChannelId, fromUserId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(map[string]string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||||
|
r1 = rf(fromChannelId, fromUserId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigratePublicChannels provides a mock function with given fields:
|
// MigratePublicChannels provides a mock function with given fields:
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user