MM-14675: Eliminates implicit GroupChannel/GroupTeam associations. (#13199)
* MM-14675: Upserts GroupTeam when GroupChannel is linked. MM-14675: Delete all associated GroupChannels when deleting a GroupTeam. MM-14675: Using replica DB where possible. MM-14675: Updates create method used in tests. * MM-14675: Removes unnecessary DB retrieval of GroupSyncable record.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0ffe199928
Коммит
75ffd0b69e
@@ -192,7 +192,7 @@ func (s *SqlGroupStore) GetByUser(userId string) ([]*model.Group, *model.AppErro
|
||||
|
||||
func (s *SqlGroupStore) Update(group *model.Group) (*model.Group, *model.AppError) {
|
||||
var retrievedGroup *model.Group
|
||||
if err := s.GetMaster().SelectOne(&retrievedGroup, "SELECT * FROM UserGroups WHERE Id = :Id", map[string]interface{}{"Id": group.Id}); err != nil {
|
||||
if err := s.GetReplica().SelectOne(&retrievedGroup, "SELECT * FROM UserGroups WHERE Id = :Id", map[string]interface{}{"Id": group.Id}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupUpdate", "store.sql_group.no_rows", nil, "id="+group.Id+","+err.Error(), http.StatusNotFound)
|
||||
}
|
||||
@@ -322,12 +322,12 @@ func (s *SqlGroupStore) UpsertMember(groupID string, userID string) (*model.Grou
|
||||
}
|
||||
|
||||
var retrievedGroup *model.Group
|
||||
if err := s.GetMaster().SelectOne(&retrievedGroup, "SELECT * FROM UserGroups WHERE Id = :Id", map[string]interface{}{"Id": groupID}); err != nil {
|
||||
if err := s.GetReplica().SelectOne(&retrievedGroup, "SELECT * FROM UserGroups WHERE Id = :Id", map[string]interface{}{"Id": groupID}); err != nil {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.insert_error", nil, "group_id="+member.GroupId+"user_id="+member.UserId+","+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var retrievedMember *model.GroupMember
|
||||
if err := s.GetMaster().SelectOne(&retrievedMember, "SELECT * FROM GroupMembers WHERE GroupId = :GroupId AND UserId = :UserId", map[string]interface{}{"GroupId": member.GroupId, "UserId": member.UserId}); err != nil {
|
||||
if err := s.GetReplica().SelectOne(&retrievedMember, "SELECT * FROM GroupMembers WHERE GroupId = :GroupId AND UserId = :UserId", map[string]interface{}{"GroupId": member.GroupId, "UserId": member.UserId}); err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.select_error", nil, "group_id="+member.GroupId+"user_id="+member.UserId+","+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
@@ -357,7 +357,7 @@ func (s *SqlGroupStore) UpsertMember(groupID string, userID string) (*model.Grou
|
||||
|
||||
func (s *SqlGroupStore) DeleteMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
|
||||
var retrievedMember *model.GroupMember
|
||||
if err := s.GetMaster().SelectOne(&retrievedMember, "SELECT * FROM GroupMembers WHERE GroupId = :GroupId AND UserId = :UserId AND DeleteAt = 0", map[string]interface{}{"GroupId": groupID, "UserId": userID}); err != nil {
|
||||
if err := s.GetReplica().SelectOne(&retrievedMember, "SELECT * FROM GroupMembers WHERE GroupId = :GroupId AND UserId = :UserId AND DeleteAt = 0", map[string]interface{}{"GroupId": groupID, "UserId": userID}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupDeleteMember", "store.sql_group.no_rows", nil, "group_id="+groupID+"user_id="+userID+","+err.Error(), http.StatusNotFound)
|
||||
}
|
||||
@@ -434,9 +434,9 @@ func (s *SqlGroupStore) getGroupSyncable(groupID string, syncableID string, sync
|
||||
|
||||
switch syncableType {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
result, err = s.GetMaster().Get(groupTeam{}, groupID, syncableID)
|
||||
result, err = s.GetReplica().Get(groupTeam{}, groupID, syncableID)
|
||||
case model.GroupSyncableTypeChannel:
|
||||
result, err = s.GetMaster().Get(groupChannel{}, groupID, syncableID)
|
||||
result, err = s.GetReplica().Get(groupChannel{}, groupID, syncableID)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -497,7 +497,7 @@ func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableTy
|
||||
GroupId = :GroupId AND GroupTeams.DeleteAt = 0`
|
||||
|
||||
results := []*groupTeamJoin{}
|
||||
_, err := s.GetMaster().Select(&results, sqlQuery, args)
|
||||
_, err := s.GetReplica().Select(&results, sqlQuery, args)
|
||||
if err != nil {
|
||||
return nil, appErrF(err.Error())
|
||||
}
|
||||
@@ -532,7 +532,7 @@ func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableTy
|
||||
GroupId = :GroupId AND GroupChannels.DeleteAt = 0`
|
||||
|
||||
results := []*groupChannelJoin{}
|
||||
_, err := s.GetMaster().Select(&results, sqlQuery, args)
|
||||
_, err := s.GetReplica().Select(&results, sqlQuery, args)
|
||||
if err != nil {
|
||||
return nil, appErrF(err.Error())
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user