Migrate Groups to not use the Layered store (#10946)
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
78b525df89
Коммит
bb2e52ee68
@@ -24,7 +24,6 @@ const (
|
|||||||
CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER = "clear_session_user"
|
CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER = "clear_session_user"
|
||||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES = "inv_roles"
|
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES = "inv_roles"
|
||||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_SCHEMES = "inv_schemes"
|
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_SCHEMES = "inv_schemes"
|
||||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_GROUPS = "inv_groups"
|
|
||||||
|
|
||||||
CLUSTER_SEND_BEST_EFFORT = "best_effort"
|
CLUSTER_SEND_BEST_EFFORT = "best_effort"
|
||||||
CLUSTER_SEND_RELIABLE = "reliable"
|
CLUSTER_SEND_RELIABLE = "reliable"
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ type LayeredStore struct {
|
|||||||
LocalCacheLayer *LocalCacheSupplier
|
LocalCacheLayer *LocalCacheSupplier
|
||||||
RedisLayer *RedisSupplier
|
RedisLayer *RedisSupplier
|
||||||
LayerChainHead LayeredStoreSupplier
|
LayerChainHead LayeredStoreSupplier
|
||||||
GroupStore GroupStore
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLayeredStore(db LayeredStoreDatabaseLayer, metrics einterfaces.MetricsInterface, cluster einterfaces.ClusterInterface) Store {
|
func NewLayeredStore(db LayeredStoreDatabaseLayer, metrics einterfaces.MetricsInterface, cluster einterfaces.ClusterInterface) Store {
|
||||||
@@ -42,7 +41,6 @@ func NewLayeredStore(db LayeredStoreDatabaseLayer, metrics einterfaces.MetricsIn
|
|||||||
store.ReactionStore = &LayeredReactionStore{store}
|
store.ReactionStore = &LayeredReactionStore{store}
|
||||||
store.RoleStore = &LayeredRoleStore{store}
|
store.RoleStore = &LayeredRoleStore{store}
|
||||||
store.SchemeStore = &LayeredSchemeStore{store}
|
store.SchemeStore = &LayeredSchemeStore{store}
|
||||||
store.GroupStore = &LayeredGroupStore{store}
|
|
||||||
|
|
||||||
// Setup the chain
|
// Setup the chain
|
||||||
if ENABLE_EXPERIMENTAL_REDIS {
|
if ENABLE_EXPERIMENTAL_REDIS {
|
||||||
@@ -188,7 +186,7 @@ func (s *LayeredStore) Scheme() SchemeStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *LayeredStore) Group() GroupStore {
|
func (s *LayeredStore) Group() GroupStore {
|
||||||
return s.GroupStore
|
return s.DatabaseLayer.Group()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *LayeredStore) LinkMetadata() LinkMetadataStore {
|
func (s *LayeredStore) LinkMetadata() LinkMetadataStore {
|
||||||
@@ -327,157 +325,3 @@ func (s *LayeredSchemeStore) PermanentDeleteAll() StoreChannel {
|
|||||||
return supplier.SchemePermanentDeleteAll(s.TmpContext)
|
return supplier.SchemePermanentDeleteAll(s.TmpContext)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type LayeredGroupStore struct {
|
|
||||||
*LayeredStore
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) Create(group *model.Group) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupCreate(s.TmpContext, group)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) Get(groupID string) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupGet(s.TmpContext, groupID)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupGetByRemoteID(s.TmpContext, remoteID, groupSource)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) GetAllBySource(groupSource model.GroupSource) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupGetAllBySource(s.TmpContext, groupSource)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) Update(group *model.Group) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupUpdate(s.TmpContext, group)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) Delete(groupID string) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupDelete(s.TmpContext, groupID)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) GetMemberUsers(groupID string) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupGetMemberUsers(s.TmpContext, groupID)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) GetMemberUsersPage(groupID string, offset int, limit int) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupGetMemberUsersPage(s.TmpContext, groupID, offset, limit)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) GetMemberCount(groupID string) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupGetMemberCount(s.TmpContext, groupID)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) CreateOrRestoreMember(groupID string, userID string) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupCreateOrRestoreMember(s.TmpContext, groupID, userID)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) DeleteMember(groupID string, userID string) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupDeleteMember(s.TmpContext, groupID, userID)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupCreateGroupSyncable(s.TmpContext, groupSyncable)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupGetGroupSyncable(s.TmpContext, groupID, syncableID, syncableType)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupGetAllGroupSyncablesByGroup(s.TmpContext, groupID, syncableType)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupUpdateGroupSyncable(s.TmpContext, groupSyncable)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GroupDeleteGroupSyncable(s.TmpContext, groupID, syncableID, syncableType)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) TeamMembersToAdd(since int64) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.TeamMembersToAdd(s.TmpContext, since)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) ChannelMembersToAdd(since int64) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.ChannelMembersToAdd(s.TmpContext, since)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) TeamMembersToRemove() StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.TeamMembersToRemove(s.TmpContext)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) ChannelMembersToRemove() StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.ChannelMembersToRemove(s.TmpContext)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GetGroupsByChannel(s.TmpContext, channelId, opts)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.CountGroupsByChannel(s.TmpContext, channelId, opts)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GetGroupsByTeam(s.TmpContext, teamId, opts)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.CountGroupsByTeam(s.TmpContext, teamId, opts)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LayeredGroupStore) GetGroups(page, perPage int, opts model.GroupSearchOpts) StoreChannel {
|
|
||||||
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
|
|
||||||
return supplier.GetGroups(s.TmpContext, page, perPage, opts)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -47,38 +47,4 @@ type LayeredStoreSupplier interface {
|
|||||||
SchemeDelete(ctx context.Context, schemeId string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
SchemeDelete(ctx context.Context, schemeId string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
||||||
SchemeGetAllPage(ctx context.Context, scope string, offset int, limit int, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
SchemeGetAllPage(ctx context.Context, scope string, offset int, limit int, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
||||||
SchemePermanentDeleteAll(ctx context.Context, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
SchemePermanentDeleteAll(ctx context.Context, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
||||||
|
|
||||||
// Groups
|
|
||||||
GroupCreate(ctx context.Context, group *model.Group, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupGet(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupGetByRemoteID(ctx context.Context, remoteID string, groupSource model.GroupSource, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupGetAllBySource(ctx context.Context, groupSource model.GroupSource, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupUpdate(ctx context.Context, group *model.Group, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupDelete(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
|
|
||||||
GroupGetMemberUsers(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupGetMemberUsersPage(ctx context.Context, groupID string, offset int, limit int, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupGetMemberCount(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupCreateOrRestoreMember(ctx context.Context, groupID string, userID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupDeleteMember(ctx context.Context, groupID string, userID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
|
|
||||||
GroupCreateGroupSyncable(ctx context.Context, groupSyncable *model.GroupSyncable, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupGetGroupSyncable(ctx context.Context, groupID string, syncableID string, syncableType model.GroupSyncableType, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupGetAllGroupSyncablesByGroup(ctx context.Context, groupID string, syncableType model.GroupSyncableType, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupUpdateGroupSyncable(ctx context.Context, groupSyncable *model.GroupSyncable, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
GroupDeleteGroupSyncable(ctx context.Context, groupID string, syncableID string, syncableType model.GroupSyncableType, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
|
|
||||||
TeamMembersToAdd(ctx context.Context, since int64, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
ChannelMembersToAdd(ctx context.Context, since int64, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
|
|
||||||
TeamMembersToRemove(ctx context.Context, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
ChannelMembersToRemove(ctx context.Context, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
|
|
||||||
GetGroupsByChannel(ctx context.Context, channelId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
CountGroupsByChannel(ctx context.Context, channelId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
|
|
||||||
GetGroupsByTeam(ctx context.Context, teamId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
CountGroupsByTeam(ctx context.Context, teamId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
|
|
||||||
GetGroups(ctx context.Context, page, perPage int, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ type LocalCacheSupplier struct {
|
|||||||
schemeCache *utils.Cache
|
schemeCache *utils.Cache
|
||||||
metrics einterfaces.MetricsInterface
|
metrics einterfaces.MetricsInterface
|
||||||
cluster einterfaces.ClusterInterface
|
cluster einterfaces.ClusterInterface
|
||||||
groupCache *utils.Cache
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Caching Interface
|
// Caching Interface
|
||||||
@@ -54,7 +53,6 @@ func NewLocalCacheSupplier(metrics einterfaces.MetricsInterface, cluster einterf
|
|||||||
reactionCache: utils.NewLruWithParams(REACTION_CACHE_SIZE, "Reaction", REACTION_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_REACTIONS),
|
reactionCache: utils.NewLruWithParams(REACTION_CACHE_SIZE, "Reaction", REACTION_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_REACTIONS),
|
||||||
roleCache: utils.NewLruWithParams(ROLE_CACHE_SIZE, "Role", ROLE_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES),
|
roleCache: utils.NewLruWithParams(ROLE_CACHE_SIZE, "Role", ROLE_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES),
|
||||||
schemeCache: utils.NewLruWithParams(SCHEME_CACHE_SIZE, "Scheme", SCHEME_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_SCHEMES),
|
schemeCache: utils.NewLruWithParams(SCHEME_CACHE_SIZE, "Scheme", SCHEME_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_SCHEMES),
|
||||||
groupCache: utils.NewLruWithParams(GROUP_CACHE_SIZE, "Group", GROUP_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_GROUPS),
|
|
||||||
metrics: metrics,
|
metrics: metrics,
|
||||||
cluster: cluster,
|
cluster: cluster,
|
||||||
}
|
}
|
||||||
@@ -62,7 +60,6 @@ func NewLocalCacheSupplier(metrics einterfaces.MetricsInterface, cluster einterf
|
|||||||
if cluster != nil {
|
if cluster != nil {
|
||||||
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_REACTIONS, supplier.handleClusterInvalidateReaction)
|
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_REACTIONS, supplier.handleClusterInvalidateReaction)
|
||||||
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES, supplier.handleClusterInvalidateRole)
|
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES, supplier.handleClusterInvalidateRole)
|
||||||
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_GROUPS, supplier.handleClusterInvalidateGroup)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return supplier
|
return supplier
|
||||||
|
|||||||
@@ -1,130 +0,0 @@
|
|||||||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
|
|
||||||
// See License.txt for license information.
|
|
||||||
|
|
||||||
package store
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) handleClusterInvalidateGroup(msg *model.ClusterMessage) {
|
|
||||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
|
||||||
s.groupCache.Purge()
|
|
||||||
} else {
|
|
||||||
s.groupCache.Remove(msg.Data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupCreate(ctx context.Context, group *model.Group, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupCreate(ctx, group, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupGet(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
if result := s.doStandardReadCache(ctx, s.groupCache, groupID, hints...); result != nil {
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
result := s.Next().GroupGet(ctx, groupID, hints...)
|
|
||||||
|
|
||||||
s.doStandardAddToCache(ctx, s.groupCache, groupID, result, hints...)
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupGetByRemoteID(ctx context.Context, remoteID string, groupSource model.GroupSource, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupGetByRemoteID(ctx, remoteID, groupSource, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupGetAllBySource(ctx context.Context, groupSource model.GroupSource, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupGetAllBySource(ctx, groupSource, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupUpdate(ctx context.Context, group *model.Group, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
defer s.doInvalidateCacheCluster(s.groupCache, group.Id)
|
|
||||||
return s.Next().GroupUpdate(ctx, group, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupDelete(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
defer s.doInvalidateCacheCluster(s.groupCache, groupID)
|
|
||||||
defer s.doClearCacheCluster(s.groupCache)
|
|
||||||
|
|
||||||
return s.Next().GroupDelete(ctx, groupID, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupGetMemberUsers(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupGetMemberUsers(ctx, groupID, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupGetMemberUsersPage(ctx context.Context, groupID string, offset int, limit int, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupGetMemberUsersPage(ctx, groupID, offset, limit, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupGetMemberCount(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupGetMemberCount(ctx, groupID, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupCreateOrRestoreMember(ctx context.Context, groupID string, userID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupCreateOrRestoreMember(ctx, groupID, userID, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupDeleteMember(ctx context.Context, groupID string, userID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupDeleteMember(ctx, groupID, userID, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupCreateGroupSyncable(ctx context.Context, groupSyncable *model.GroupSyncable, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupCreateGroupSyncable(ctx, groupSyncable, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupGetGroupSyncable(ctx context.Context, groupID string, syncableID string, syncableType model.GroupSyncableType, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupGetGroupSyncable(ctx, groupID, syncableID, syncableType, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupGetAllGroupSyncablesByGroup(ctx context.Context, groupID string, syncableType model.GroupSyncableType, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupGetAllGroupSyncablesByGroup(ctx, groupID, syncableType, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupUpdateGroupSyncable(ctx context.Context, groupSyncable *model.GroupSyncable, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupUpdateGroupSyncable(ctx, groupSyncable, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GroupDeleteGroupSyncable(ctx context.Context, groupID string, syncableID string, syncableType model.GroupSyncableType, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GroupDeleteGroupSyncable(ctx, groupID, syncableID, syncableType, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) TeamMembersToAdd(ctx context.Context, since int64, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().TeamMembersToAdd(ctx, since, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) ChannelMembersToAdd(ctx context.Context, since int64, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().ChannelMembersToAdd(ctx, since, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) TeamMembersToRemove(ctx context.Context, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().TeamMembersToRemove(ctx, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) ChannelMembersToRemove(ctx context.Context, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().ChannelMembersToRemove(ctx, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GetGroupsByChannel(ctx context.Context, channelId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GetGroupsByChannel(ctx, channelId, opts, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) CountGroupsByChannel(ctx context.Context, channelId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().CountGroupsByChannel(ctx, channelId, opts, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GetGroupsByTeam(ctx context.Context, teamId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GetGroupsByTeam(ctx, teamId, opts, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) CountGroupsByTeam(ctx context.Context, teamId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().CountGroupsByTeam(ctx, teamId, opts, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *LocalCacheSupplier) GetGroups(ctx context.Context, page, perPage int, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
return s.Next().GetGroups(ctx, page, perPage, opts, hints...)
|
|
||||||
}
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
|
|
||||||
// See License.txt for license information.
|
|
||||||
|
|
||||||
package store
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupCreate(ctx context.Context, group *model.Group, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupCreate(ctx, group, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupGet(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupGet(ctx, groupID, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupGetByRemoteID(ctx context.Context, remoteID string, groupSource model.GroupSource, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupGetByRemoteID(ctx, remoteID, groupSource, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupGetAllBySource(ctx context.Context, groupSource model.GroupSource, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupGetAllBySource(ctx, groupSource, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupUpdate(ctx context.Context, group *model.Group, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupUpdate(ctx, group, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupDelete(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupDelete(ctx, groupID, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupGetMemberUsers(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupGetMemberUsers(ctx, groupID, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupGetMemberUsersPage(ctx context.Context, groupID string, offset int, limit int, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupGetMemberUsersPage(ctx, groupID, offset, limit, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupGetMemberCount(ctx context.Context, groupID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupGetMemberCount(ctx, groupID, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupCreateOrRestoreMember(ctx context.Context, groupID string, userID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupCreateOrRestoreMember(ctx, groupID, userID, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupDeleteMember(ctx context.Context, groupID string, userID string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupDeleteMember(ctx, groupID, userID, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupCreateGroupSyncable(ctx context.Context, groupSyncable *model.GroupSyncable, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupCreateGroupSyncable(ctx, groupSyncable, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupGetGroupSyncable(ctx context.Context, groupID string, syncableID string, syncableType model.GroupSyncableType, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupGetGroupSyncable(ctx, groupID, syncableID, syncableType, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupGetAllGroupSyncablesByGroup(ctx context.Context, groupID string, syncableType model.GroupSyncableType, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupGetAllGroupSyncablesByGroup(ctx, groupID, syncableType, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupUpdateGroupSyncable(ctx context.Context, groupSyncable *model.GroupSyncable, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupUpdateGroupSyncable(ctx, groupSyncable, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GroupDeleteGroupSyncable(ctx context.Context, groupID string, syncableID string, syncableType model.GroupSyncableType, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GroupDeleteGroupSyncable(ctx, groupID, syncableID, syncableType, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) TeamMembersToAdd(ctx context.Context, since int64, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().TeamMembersToAdd(ctx, since, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) ChannelMembersToAdd(ctx context.Context, since int64, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().ChannelMembersToAdd(ctx, since, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) TeamMembersToRemove(ctx context.Context, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().TeamMembersToRemove(ctx, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) ChannelMembersToRemove(ctx context.Context, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().ChannelMembersToRemove(ctx, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GetGroupsByChannel(ctx context.Context, channelId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GetGroupsByChannel(ctx, channelId, opts, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) CountGroupsByChannel(ctx context.Context, channelId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().CountGroupsByChannel(ctx, channelId, opts, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GetGroupsByTeam(ctx context.Context, teamId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GetGroupsByTeam(ctx, teamId, opts, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) CountGroupsByTeam(ctx context.Context, teamId string, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().CountGroupsByTeam(ctx, teamId, opts, hints...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *RedisSupplier) GetGroups(ctx context.Context, page, perPage int, opts model.GroupSearchOpts, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
||||||
// TODO: Redis caching.
|
|
||||||
return s.Next().GetGroups(ctx, page, perPage, opts, hints...)
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
package sqlstore
|
package sqlstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -47,7 +46,12 @@ type groupChannelJoin struct {
|
|||||||
TeamID string `db:"TeamId"`
|
TeamID string `db:"TeamId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func initSqlSupplierGroups(sqlStore SqlStore) {
|
type SqlGroupStore struct {
|
||||||
|
SqlStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSqlGroupStore(sqlStore SqlStore) store.GroupStore {
|
||||||
|
s := &SqlGroupStore{SqlStore: sqlStore}
|
||||||
for _, db := range sqlStore.GetAllConns() {
|
for _, db := range sqlStore.GetAllConns() {
|
||||||
groups := db.AddTableWithName(model.Group{}, "UserGroups").SetKeys(false, "Id")
|
groups := db.AddTableWithName(model.Group{}, "UserGroups").SetKeys(false, "Id")
|
||||||
groups.ColMap("Id").SetMaxSize(26)
|
groups.ColMap("Id").SetMaxSize(26)
|
||||||
@@ -70,25 +74,26 @@ func initSqlSupplierGroups(sqlStore SqlStore) {
|
|||||||
groupChannels.ColMap("GroupId").SetMaxSize(26)
|
groupChannels.ColMap("GroupId").SetMaxSize(26)
|
||||||
groupChannels.ColMap("ChannelId").SetMaxSize(26)
|
groupChannels.ColMap("ChannelId").SetMaxSize(26)
|
||||||
}
|
}
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) CreateIndexesIfNotExistsGroups() {
|
func (s *SqlGroupStore) CreateIndexesIfNotExists() {
|
||||||
s.CreateIndexIfNotExists("idx_groupmembers_create_at", "GroupMembers", "CreateAt")
|
s.CreateIndexIfNotExists("idx_groupmembers_create_at", "GroupMembers", "CreateAt")
|
||||||
s.CreateIndexIfNotExists("idx_usergroups_remote_id", "UserGroups", "RemoteId")
|
s.CreateIndexIfNotExists("idx_usergroups_remote_id", "UserGroups", "RemoteId")
|
||||||
s.CreateIndexIfNotExists("idx_usergroups_delete_at", "UserGroups", "DeleteAt")
|
s.CreateIndexIfNotExists("idx_usergroups_delete_at", "UserGroups", "DeleteAt")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupCreate(ctx context.Context, group *model.Group, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) Create(group *model.Group) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
if len(group.Id) != 0 {
|
if len(group.Id) != 0 {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreate", "model.group.id.app_error", nil, "", http.StatusBadRequest)
|
result.Err = model.NewAppError("SqlGroupStore.GroupCreate", "model.group.id.app_error", nil, "", http.StatusBadRequest)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := group.IsValidForCreate(); err != nil {
|
if err := group.IsValidForCreate(); err != nil {
|
||||||
result.Err = err
|
result.Err = err
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
group.Id = model.NewId()
|
group.Id = model.NewId()
|
||||||
@@ -101,15 +106,16 @@ func (s *SqlSupplier) GroupCreate(ctx context.Context, group *model.Group, hints
|
|||||||
} else {
|
} else {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreate", "store.insert_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupCreate", "store.insert_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = group
|
result.Data = group
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupGet(ctx context.Context, groupId string, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) Get(groupId string) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
var group *model.Group
|
var group *model.Group
|
||||||
if err := s.GetReplica().SelectOne(&group, "SELECT * from UserGroups WHERE Id = :Id", map[string]interface{}{"Id": groupId}); err != nil {
|
if err := s.GetReplica().SelectOne(&group, "SELECT * from UserGroups WHERE Id = :Id", map[string]interface{}{"Id": groupId}); err != nil {
|
||||||
@@ -118,15 +124,16 @@ func (s *SqlSupplier) GroupGet(ctx context.Context, groupId string, hints ...sto
|
|||||||
} else {
|
} else {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupGet", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupGet", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = group
|
result.Data = group
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupGetByRemoteID(ctx context.Context, remoteID string, groupSource model.GroupSource, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSource) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
var group *model.Group
|
var group *model.Group
|
||||||
if err := s.GetReplica().SelectOne(&group, "SELECT * from UserGroups WHERE RemoteId = :RemoteId AND Source = :Source", map[string]interface{}{"RemoteId": remoteID, "Source": groupSource}); err != nil {
|
if err := s.GetReplica().SelectOne(&group, "SELECT * from UserGroups WHERE RemoteId = :RemoteId AND Source = :Source", map[string]interface{}{"RemoteId": remoteID, "Source": groupSource}); err != nil {
|
||||||
@@ -135,30 +142,32 @@ func (s *SqlSupplier) GroupGetByRemoteID(ctx context.Context, remoteID string, g
|
|||||||
} else {
|
} else {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupGetByRemoteID", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupGetByRemoteID", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = group
|
result.Data = group
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupGetAllBySource(ctx context.Context, groupSource model.GroupSource, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) GetAllBySource(groupSource model.GroupSource) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
var groups []*model.Group
|
var groups []*model.Group
|
||||||
|
|
||||||
if _, err := s.GetReplica().Select(&groups, "SELECT * from UserGroups WHERE DeleteAt = 0 AND Source = :Source", map[string]interface{}{"Source": groupSource}); err != nil {
|
if _, err := s.GetReplica().Select(&groups, "SELECT * from UserGroups WHERE DeleteAt = 0 AND Source = :Source", map[string]interface{}{"Source": groupSource}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupGetAllBySource", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupGetAllBySource", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = groups
|
result.Data = groups
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupUpdate(ctx context.Context, group *model.Group, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) Update(group *model.Group) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
var retrievedGroup *model.Group
|
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.GetMaster().SelectOne(&retrievedGroup, "SELECT * FROM UserGroups WHERE Id = :Id", map[string]interface{}{"Id": group.Id}); err != nil {
|
||||||
@@ -167,13 +176,13 @@ func (s *SqlSupplier) GroupUpdate(ctx context.Context, group *model.Group, hints
|
|||||||
} else {
|
} else {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdate", "store.select_error", nil, "id="+group.Id+","+err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupUpdate", "store.select_error", nil, "id="+group.Id+","+err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If updating DeleteAt it can only be to 0
|
// If updating DeleteAt it can only be to 0
|
||||||
if group.DeleteAt != retrievedGroup.DeleteAt && group.DeleteAt != 0 {
|
if group.DeleteAt != retrievedGroup.DeleteAt && group.DeleteAt != 0 {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdate", "model.group.delete_at.app_error", nil, "", http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupUpdate", "model.group.delete_at.app_error", nil, "", http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset these properties, don't update them based on input
|
// Reset these properties, don't update them based on input
|
||||||
@@ -182,25 +191,26 @@ func (s *SqlSupplier) GroupUpdate(ctx context.Context, group *model.Group, hints
|
|||||||
|
|
||||||
if err := group.IsValidForUpdate(); err != nil {
|
if err := group.IsValidForUpdate(); err != nil {
|
||||||
result.Err = err
|
result.Err = err
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rowsChanged, err := s.GetMaster().Update(group)
|
rowsChanged, err := s.GetMaster().Update(group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdate", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupUpdate", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
if rowsChanged != 1 {
|
if rowsChanged != 1 {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdate", "store.sql_group.no_rows_changed", nil, "", http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupUpdate", "store.sql_group.no_rows_changed", nil, "", http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = group
|
result.Data = group
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupDelete(ctx context.Context, groupID string, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) Delete(groupID string) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
var group *model.Group
|
var group *model.Group
|
||||||
if err := s.GetReplica().SelectOne(&group, "SELECT * from UserGroups WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": groupID}); err != nil {
|
if err := s.GetReplica().SelectOne(&group, "SELECT * from UserGroups WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": groupID}); err != nil {
|
||||||
@@ -210,7 +220,7 @@ func (s *SqlSupplier) GroupDelete(ctx context.Context, groupID string, hints ...
|
|||||||
result.Err = model.NewAppError("SqlGroupStore.GroupDelete", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupDelete", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
time := model.GetMillis()
|
time := model.GetMillis()
|
||||||
@@ -222,11 +232,12 @@ func (s *SqlSupplier) GroupDelete(ctx context.Context, groupID string, hints ...
|
|||||||
}
|
}
|
||||||
|
|
||||||
result.Data = group
|
result.Data = group
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupGetMemberUsers(stc context.Context, groupID string, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) GetMemberUsers(groupID string) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
var groupMembers []*model.User
|
var groupMembers []*model.User
|
||||||
|
|
||||||
@@ -243,16 +254,17 @@ func (s *SqlSupplier) GroupGetMemberUsers(stc context.Context, groupID string, h
|
|||||||
|
|
||||||
if _, err := s.GetReplica().Select(&groupMembers, query, map[string]interface{}{"GroupId": groupID}); err != nil {
|
if _, err := s.GetReplica().Select(&groupMembers, query, map[string]interface{}{"GroupId": groupID}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupGetAllBySource", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupGetAllBySource", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = groupMembers
|
result.Data = groupMembers
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupGetMemberUsersPage(stc context.Context, groupID string, offset int, limit int, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) GetMemberUsersPage(groupID string, offset int, limit int) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
var groupMembers []*model.User
|
var groupMembers []*model.User
|
||||||
|
|
||||||
@@ -275,16 +287,17 @@ func (s *SqlSupplier) GroupGetMemberUsersPage(stc context.Context, groupID strin
|
|||||||
|
|
||||||
if _, err := s.GetReplica().Select(&groupMembers, query, map[string]interface{}{"GroupId": groupID, "Limit": limit, "Offset": offset}); err != nil {
|
if _, err := s.GetReplica().Select(&groupMembers, query, map[string]interface{}{"GroupId": groupID, "Limit": limit, "Offset": offset}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupGetMemberUsersPage", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupGetMemberUsersPage", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = groupMembers
|
result.Data = groupMembers
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupGetMemberCount(stc context.Context, groupID string, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) GetMemberCount(groupID string) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
var count int64
|
var count int64
|
||||||
var err error
|
var err error
|
||||||
@@ -299,16 +312,17 @@ func (s *SqlSupplier) GroupGetMemberCount(stc context.Context, groupID string, h
|
|||||||
|
|
||||||
if count, err = s.GetReplica().SelectInt(query, map[string]interface{}{"GroupId": groupID}); err != nil {
|
if count, err = s.GetReplica().SelectInt(query, map[string]interface{}{"GroupId": groupID}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupGetMemberUsersPage", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupGetMemberUsersPage", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = count
|
result.Data = count
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupCreateOrRestoreMember(ctx context.Context, groupID string, userID string, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) CreateOrRestoreMember(groupID string, userID string) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
member := &model.GroupMember{
|
member := &model.GroupMember{
|
||||||
GroupId: groupID,
|
GroupId: groupID,
|
||||||
@@ -317,36 +331,36 @@ func (s *SqlSupplier) GroupCreateOrRestoreMember(ctx context.Context, groupID st
|
|||||||
}
|
}
|
||||||
|
|
||||||
if result.Err = member.IsValid(); result.Err != nil {
|
if result.Err = member.IsValid(); result.Err != nil {
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var retrievedGroup *model.Group
|
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.GetMaster().SelectOne(&retrievedGroup, "SELECT * FROM UserGroups WHERE Id = :Id", map[string]interface{}{"Id": groupID}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.insert_error", nil, "group_id="+member.GroupId+"user_id="+member.UserId+","+err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.insert_error", nil, "group_id="+member.GroupId+"user_id="+member.UserId+","+err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var retrievedMember *model.GroupMember
|
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.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 != sql.ErrNoRows {
|
if err != sql.ErrNoRows {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.select_error", nil, "group_id="+member.GroupId+"user_id="+member.UserId+","+err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.select_error", nil, "group_id="+member.GroupId+"user_id="+member.UserId+","+err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if retrievedMember != nil && retrievedMember.DeleteAt == 0 {
|
if retrievedMember != nil && retrievedMember.DeleteAt == 0 {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.sql_group.uniqueness_error", nil, "group_id="+member.GroupId+", user_id="+member.UserId, http.StatusBadRequest)
|
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.sql_group.uniqueness_error", nil, "group_id="+member.GroupId+", user_id="+member.UserId, http.StatusBadRequest)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if retrievedMember == nil {
|
if retrievedMember == nil {
|
||||||
if err := s.GetMaster().Insert(member); err != nil {
|
if err := s.GetMaster().Insert(member); err != nil {
|
||||||
if IsUniqueConstraintError(err, []string{"GroupId", "UserId", "groupmembers_pkey", "PRIMARY"}) {
|
if IsUniqueConstraintError(err, []string{"GroupId", "UserId", "groupmembers_pkey", "PRIMARY"}) {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.sql_group.uniqueness_error", nil, "group_id="+member.GroupId+", user_id="+member.UserId+", "+err.Error(), http.StatusBadRequest)
|
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.sql_group.uniqueness_error", nil, "group_id="+member.GroupId+", user_id="+member.UserId+", "+err.Error(), http.StatusBadRequest)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.insert_error", nil, "group_id="+member.GroupId+", user_id="+member.UserId+", "+err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.insert_error", nil, "group_id="+member.GroupId+", user_id="+member.UserId+", "+err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
member.DeleteAt = 0
|
member.DeleteAt = 0
|
||||||
@@ -354,48 +368,50 @@ func (s *SqlSupplier) GroupCreateOrRestoreMember(ctx context.Context, groupID st
|
|||||||
var err error
|
var err error
|
||||||
if rowsChanged, err = s.GetMaster().Update(member); err != nil {
|
if rowsChanged, err = s.GetMaster().Update(member); err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.update_error", nil, "group_id="+member.GroupId+", user_id="+member.UserId+", "+err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.update_error", nil, "group_id="+member.GroupId+", user_id="+member.UserId+", "+err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
if rowsChanged != 1 {
|
if rowsChanged != 1 {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.sql_group.no_rows_changed", nil, "", http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupCreateOrRestoreMember", "store.sql_group.no_rows_changed", nil, "", http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = member
|
result.Data = member
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupDeleteMember(ctx context.Context, groupID string, userID string, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) DeleteMember(groupID string, userID string) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
var retrievedMember *model.GroupMember
|
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.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 == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteMember", "store.sql_group.no_rows", nil, "group_id="+groupID+"user_id="+userID+","+err.Error(), http.StatusNotFound)
|
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteMember", "store.sql_group.no_rows", nil, "group_id="+groupID+"user_id="+userID+","+err.Error(), http.StatusNotFound)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteMember", "store.select_error", nil, "group_id="+groupID+"user_id="+userID+","+err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteMember", "store.select_error", nil, "group_id="+groupID+"user_id="+userID+","+err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
retrievedMember.DeleteAt = model.GetMillis()
|
retrievedMember.DeleteAt = model.GetMillis()
|
||||||
|
|
||||||
if _, err := s.GetMaster().Update(retrievedMember); err != nil {
|
if _, err := s.GetMaster().Update(retrievedMember); err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteMember", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteMember", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = retrievedMember
|
result.Data = retrievedMember
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupCreateGroupSyncable(ctx context.Context, groupSyncable *model.GroupSyncable, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
if err := groupSyncable.IsValid(); err != nil {
|
if err := groupSyncable.IsValid(); err != nil {
|
||||||
result.Err = err
|
result.Err = err
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset values that shouldn't be updatable by parameter
|
// Reset values that shouldn't be updatable by parameter
|
||||||
@@ -409,7 +425,7 @@ func (s *SqlSupplier) GroupCreateGroupSyncable(ctx context.Context, groupSyncabl
|
|||||||
case model.GroupSyncableTypeTeam:
|
case model.GroupSyncableTypeTeam:
|
||||||
if _, err := s.Team().Get(groupSyncable.SyncableId); err != nil {
|
if _, err := s.Team().Get(groupSyncable.SyncableId); err != nil {
|
||||||
result.Err = err
|
result.Err = err
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable))
|
err = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable))
|
||||||
@@ -417,26 +433,27 @@ func (s *SqlSupplier) GroupCreateGroupSyncable(ctx context.Context, groupSyncabl
|
|||||||
_, errCh := s.Channel().Get(groupSyncable.SyncableId, false)
|
_, errCh := s.Channel().Get(groupSyncable.SyncableId, false)
|
||||||
if errCh != nil {
|
if errCh != nil {
|
||||||
result.Err = errCh
|
result.Err = errCh
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.GetMaster().Insert(groupSyncableToGroupChannel(groupSyncable))
|
err = s.GetMaster().Insert(groupSyncableToGroupChannel(groupSyncable))
|
||||||
default:
|
default:
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreateGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupCreateGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreateGroupSyncable", "store.insert_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupCreateGroupSyncable", "store.insert_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = groupSyncable
|
result.Data = groupSyncable
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupGetGroupSyncable(ctx context.Context, groupID string, syncableID string, syncableType model.GroupSyncableType, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
groupSyncable, err := s.getGroupSyncable(groupID, syncableID, syncableType)
|
groupSyncable, err := s.getGroupSyncable(groupID, syncableID, syncableType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -445,15 +462,16 @@ func (s *SqlSupplier) GroupGetGroupSyncable(ctx context.Context, groupID string,
|
|||||||
} else {
|
} else {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupGetGroupSyncable", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupGetGroupSyncable", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = groupSyncable
|
result.Data = groupSyncable
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) getGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) {
|
func (s *SqlGroupStore) getGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) {
|
||||||
var err error
|
var err error
|
||||||
var result interface{}
|
var result interface{}
|
||||||
|
|
||||||
@@ -499,8 +517,8 @@ func (s *SqlSupplier) getGroupSyncable(groupID string, syncableID string, syncab
|
|||||||
return &groupSyncable, nil
|
return &groupSyncable, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupGetAllGroupSyncablesByGroup(ctx context.Context, groupID string, syncableType model.GroupSyncableType, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
args := map[string]interface{}{"GroupId": groupID}
|
args := map[string]interface{}{"GroupId": groupID}
|
||||||
|
|
||||||
@@ -527,7 +545,7 @@ func (s *SqlSupplier) GroupGetAllGroupSyncablesByGroup(ctx context.Context, grou
|
|||||||
_, err := s.GetMaster().Select(&results, sqlQuery, args)
|
_, err := s.GetMaster().Select(&results, sqlQuery, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = appErrF(err.Error())
|
result.Err = appErrF(err.Error())
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
groupSyncable := &model.GroupSyncable{
|
groupSyncable := &model.GroupSyncable{
|
||||||
@@ -563,7 +581,7 @@ func (s *SqlSupplier) GroupGetAllGroupSyncablesByGroup(ctx context.Context, grou
|
|||||||
_, err := s.GetMaster().Select(&results, sqlQuery, args)
|
_, err := s.GetMaster().Select(&results, sqlQuery, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = appErrF(err.Error())
|
result.Err = appErrF(err.Error())
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
groupSyncable := &model.GroupSyncable{
|
groupSyncable := &model.GroupSyncable{
|
||||||
@@ -585,31 +603,32 @@ func (s *SqlSupplier) GroupGetAllGroupSyncablesByGroup(ctx context.Context, grou
|
|||||||
}
|
}
|
||||||
|
|
||||||
result.Data = groupSyncables
|
result.Data = groupSyncables
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupUpdateGroupSyncable(ctx context.Context, groupSyncable *model.GroupSyncable, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
retrievedGroupSyncable, err := s.getGroupSyncable(groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type)
|
retrievedGroupSyncable, err := s.getGroupSyncable(groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.sql_group.no_rows", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.sql_group.no_rows", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.select_error", nil, "GroupId="+groupSyncable.GroupId+", SyncableId="+groupSyncable.SyncableId+", SyncableType="+groupSyncable.Type.String()+", "+err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.select_error", nil, "GroupId="+groupSyncable.GroupId+", SyncableId="+groupSyncable.SyncableId+", SyncableType="+groupSyncable.Type.String()+", "+err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := groupSyncable.IsValid(); err != nil {
|
if err := groupSyncable.IsValid(); err != nil {
|
||||||
result.Err = err
|
result.Err = err
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If updating DeleteAt it can only be to 0
|
// If updating DeleteAt it can only be to 0
|
||||||
if groupSyncable.DeleteAt != retrievedGroupSyncable.DeleteAt && groupSyncable.DeleteAt != 0 {
|
if groupSyncable.DeleteAt != retrievedGroupSyncable.DeleteAt && groupSyncable.DeleteAt != 0 {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "model.group.delete_at.app_error", nil, "", http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "model.group.delete_at.app_error", nil, "", http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset these properties, don't update them based on input
|
// Reset these properties, don't update them based on input
|
||||||
@@ -623,20 +642,21 @@ func (s *SqlSupplier) GroupUpdateGroupSyncable(ctx context.Context, groupSyncabl
|
|||||||
_, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable))
|
_, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable))
|
||||||
default:
|
default:
|
||||||
model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = groupSyncable
|
result.Data = groupSyncable
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GroupDeleteGroupSyncable(ctx context.Context, groupID string, syncableID string, syncableType model.GroupSyncableType, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
groupSyncable, err := s.getGroupSyncable(groupID, syncableID, syncableType)
|
groupSyncable, err := s.getGroupSyncable(groupID, syncableID, syncableType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -645,12 +665,12 @@ func (s *SqlSupplier) GroupDeleteGroupSyncable(ctx context.Context, groupID stri
|
|||||||
} else {
|
} else {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if groupSyncable.DeleteAt != 0 {
|
if groupSyncable.DeleteAt != 0 {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.sql_group.group_syncable_already_deleted", nil, "group_id="+groupID+"syncable_id="+syncableID, http.StatusBadRequest)
|
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.sql_group.group_syncable_already_deleted", nil, "group_id="+groupID+"syncable_id="+syncableID, http.StatusBadRequest)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
time := model.GetMillis()
|
time := model.GetMillis()
|
||||||
@@ -664,24 +684,25 @@ func (s *SqlSupplier) GroupDeleteGroupSyncable(ctx context.Context, groupID stri
|
|||||||
_, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable))
|
_, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable))
|
||||||
default:
|
default:
|
||||||
model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = groupSyncable
|
result.Data = groupSyncable
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TeamMembersToAdd returns a slice of UserTeamIDPair that need newly created memberships
|
// TeamMembersToAdd returns a slice of UserTeamIDPair that need newly created memberships
|
||||||
// based on the groups configurations.
|
// based on the groups configurations.
|
||||||
//
|
//
|
||||||
// Typically since will be the last successful group sync time.
|
// Typically since will be the last successful group sync time.
|
||||||
func (s *SqlSupplier) TeamMembersToAdd(ctx context.Context, since int64, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) TeamMembersToAdd(since int64) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
sql := `
|
sql := `
|
||||||
SELECT
|
SELECT
|
||||||
@@ -715,15 +736,16 @@ func (s *SqlSupplier) TeamMembersToAdd(ctx context.Context, since int64, hints .
|
|||||||
|
|
||||||
result.Data = teamMembers
|
result.Data = teamMembers
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelMembersToAdd returns a slice of UserChannelIDPair that need newly created memberships
|
// ChannelMembersToAdd returns a slice of UserChannelIDPair that need newly created memberships
|
||||||
// based on the groups configurations.
|
// based on the groups configurations.
|
||||||
//
|
//
|
||||||
// Typically since will be the last successful group sync time.
|
// Typically since will be the last successful group sync time.
|
||||||
func (s *SqlSupplier) ChannelMembersToAdd(ctx context.Context, since int64, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) ChannelMembersToAdd(since int64) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
sql := `
|
sql := `
|
||||||
SELECT
|
SELECT
|
||||||
@@ -757,7 +779,8 @@ func (s *SqlSupplier) ChannelMembersToAdd(ctx context.Context, since int64, hint
|
|||||||
|
|
||||||
result.Data = channelMembers
|
result.Data = channelMembers
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func groupSyncableToGroupTeam(groupSyncable *model.GroupSyncable) *groupTeam {
|
func groupSyncableToGroupTeam(groupSyncable *model.GroupSyncable) *groupTeam {
|
||||||
@@ -775,8 +798,8 @@ func groupSyncableToGroupChannel(groupSyncable *model.GroupSyncable) *groupChann
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TeamMembersToRemove returns all team members that should be removed based on group constraints.
|
// TeamMembersToRemove returns all team members that should be removed based on group constraints.
|
||||||
func (s *SqlSupplier) TeamMembersToRemove(ctx context.Context, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) TeamMembersToRemove() store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
sql := `
|
sql := `
|
||||||
SELECT
|
SELECT
|
||||||
@@ -824,33 +847,35 @@ func (s *SqlSupplier) TeamMembersToRemove(ctx context.Context, hints ...store.La
|
|||||||
|
|
||||||
result.Data = teamMembers
|
result.Data = teamMembers
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) CountGroupsByChannel(ctx context.Context, channelId string, opts model.GroupSearchOpts, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
countQuery := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeChannel, selectCountGroups, channelId, opts)
|
countQuery := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeChannel, selectCountGroups, channelId, opts)
|
||||||
|
|
||||||
countQueryString, args, err := countQuery.ToSql()
|
countQueryString, args, err := countQuery.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.CountGroupsByChannel", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.CountGroupsByChannel", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := s.GetReplica().SelectInt(countQueryString, args...)
|
count, err := s.GetReplica().SelectInt(countQueryString, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.CountGroupsByChannel", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.CountGroupsByChannel", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = count
|
result.Data = count
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GetGroupsByChannel(ctx context.Context, channelId string, opts model.GroupSearchOpts, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
query := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeChannel, selectGroups, channelId, opts)
|
query := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeChannel, selectGroups, channelId, opts)
|
||||||
|
|
||||||
@@ -862,7 +887,7 @@ func (s *SqlSupplier) GetGroupsByChannel(ctx context.Context, channelId string,
|
|||||||
queryString, args, err := query.ToSql()
|
queryString, args, err := query.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GetGroupsByChannel", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GetGroupsByChannel", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var groups []*model.Group
|
var groups []*model.Group
|
||||||
@@ -870,17 +895,18 @@ func (s *SqlSupplier) GetGroupsByChannel(ctx context.Context, channelId string,
|
|||||||
_, err = s.GetReplica().Select(&groups, queryString, args...)
|
_, err = s.GetReplica().Select(&groups, queryString, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GetGroupsByChannel", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GetGroupsByChannel", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = groups
|
result.Data = groups
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelMembersToRemove returns all channel members that should be removed based on group constraints.
|
// ChannelMembersToRemove returns all channel members that should be removed based on group constraints.
|
||||||
func (s *SqlSupplier) ChannelMembersToRemove(ctx context.Context, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) ChannelMembersToRemove() store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
sql := `
|
sql := `
|
||||||
SELECT
|
SELECT
|
||||||
@@ -931,10 +957,11 @@ func (s *SqlSupplier) ChannelMembersToRemove(ctx context.Context, hints ...store
|
|||||||
|
|
||||||
result.Data = channelMembers
|
result.Data = channelMembers
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) groupsBySyncableBaseQuery(st model.GroupSyncableType, t selectType, syncableID string, opts model.GroupSearchOpts) squirrel.SelectBuilder {
|
func (s *SqlGroupStore) groupsBySyncableBaseQuery(st model.GroupSyncableType, t selectType, syncableID string, opts model.GroupSearchOpts) squirrel.SelectBuilder {
|
||||||
selectStrs := map[selectType]string{
|
selectStrs := map[selectType]string{
|
||||||
selectGroups: "ug.*",
|
selectGroups: "ug.*",
|
||||||
selectCountGroups: "COUNT(*)",
|
selectCountGroups: "COUNT(*)",
|
||||||
@@ -978,30 +1005,31 @@ func (s *SqlSupplier) groupsBySyncableBaseQuery(st model.GroupSyncableType, t se
|
|||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) CountGroupsByTeam(ctx context.Context, teamId string, opts model.GroupSearchOpts, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
countQuery := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeTeam, selectCountGroups, teamId, opts)
|
countQuery := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeTeam, selectCountGroups, teamId, opts)
|
||||||
|
|
||||||
countQueryString, args, err := countQuery.ToSql()
|
countQueryString, args, err := countQuery.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.CountGroupsByTeam", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.CountGroupsByTeam", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := s.GetReplica().SelectInt(countQueryString, args...)
|
count, err := s.GetReplica().SelectInt(countQueryString, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.CountGroupsByTeam", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.CountGroupsByTeam", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = count
|
result.Data = count
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GetGroupsByTeam(ctx context.Context, teamId string, opts model.GroupSearchOpts, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
|
|
||||||
query := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeTeam, selectGroups, teamId, opts)
|
query := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeTeam, selectGroups, teamId, opts)
|
||||||
|
|
||||||
@@ -1013,7 +1041,7 @@ func (s *SqlSupplier) GetGroupsByTeam(ctx context.Context, teamId string, opts m
|
|||||||
queryString, args, err := query.ToSql()
|
queryString, args, err := query.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GetGroupsByTeam", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GetGroupsByTeam", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var groups []*model.Group
|
var groups []*model.Group
|
||||||
@@ -1021,16 +1049,17 @@ func (s *SqlSupplier) GetGroupsByTeam(ctx context.Context, teamId string, opts m
|
|||||||
_, err = s.GetReplica().Select(&groups, queryString, args...)
|
_, err = s.GetReplica().Select(&groups, queryString, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GetGroupsByTeam", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GetGroupsByTeam", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = groups
|
result.Data = groups
|
||||||
|
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlSupplier) GetGroups(ctx context.Context, page, perPage int, opts model.GroupSearchOpts, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult {
|
func (s *SqlGroupStore) GetGroups(page, perPage int, opts model.GroupSearchOpts) store.StoreChannel {
|
||||||
result := store.NewSupplierResult()
|
return store.Do(func(result *store.StoreResult) {
|
||||||
var groups []*model.Group
|
var groups []*model.Group
|
||||||
|
|
||||||
groupsQuery := s.getQueryBuilder().Select("g.*").From("UserGroups g").Limit(uint64(perPage)).Offset(uint64(page * perPage)).OrderBy("g.DisplayName")
|
groupsQuery := s.getQueryBuilder().Select("g.*").From("UserGroups g").Limit(uint64(perPage)).Offset(uint64(page * perPage)).OrderBy("g.DisplayName")
|
||||||
@@ -1089,14 +1118,15 @@ func (s *SqlSupplier) GetGroups(ctx context.Context, page, perPage int, opts mod
|
|||||||
queryString, args, err := groupsQuery.ToSql()
|
queryString, args, err := groupsQuery.ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GetGroups", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GetGroups", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = s.GetReplica().Select(&groups, queryString, args...); err != nil {
|
if _, err = s.GetReplica().Select(&groups, queryString, args...); err != nil {
|
||||||
result.Err = model.NewAppError("SqlGroupStore.GetGroups", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
result.Err = model.NewAppError("SqlGroupStore.GetGroups", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return result
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = groups
|
result.Data = groups
|
||||||
return result
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,11 +151,11 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter
|
|||||||
supplier.oldStores.TermsOfService = NewSqlTermsOfServiceStore(supplier, metrics)
|
supplier.oldStores.TermsOfService = NewSqlTermsOfServiceStore(supplier, metrics)
|
||||||
supplier.oldStores.UserTermsOfService = NewSqlUserTermsOfServiceStore(supplier)
|
supplier.oldStores.UserTermsOfService = NewSqlUserTermsOfServiceStore(supplier)
|
||||||
supplier.oldStores.linkMetadata = NewSqlLinkMetadataStore(supplier)
|
supplier.oldStores.linkMetadata = NewSqlLinkMetadataStore(supplier)
|
||||||
|
supplier.oldStores.group = NewSqlGroupStore(supplier)
|
||||||
|
|
||||||
initSqlSupplierReactions(supplier)
|
initSqlSupplierReactions(supplier)
|
||||||
initSqlSupplierRoles(supplier)
|
initSqlSupplierRoles(supplier)
|
||||||
initSqlSupplierSchemes(supplier)
|
initSqlSupplierSchemes(supplier)
|
||||||
initSqlSupplierGroups(supplier)
|
|
||||||
|
|
||||||
err := supplier.GetMaster().CreateTablesIfNotExists()
|
err := supplier.GetMaster().CreateTablesIfNotExists()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -196,8 +196,7 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter
|
|||||||
supplier.oldStores.TermsOfService.(SqlTermsOfServiceStore).CreateIndexesIfNotExists()
|
supplier.oldStores.TermsOfService.(SqlTermsOfServiceStore).CreateIndexesIfNotExists()
|
||||||
supplier.oldStores.UserTermsOfService.(SqlUserTermsOfServiceStore).CreateIndexesIfNotExists()
|
supplier.oldStores.UserTermsOfService.(SqlUserTermsOfServiceStore).CreateIndexesIfNotExists()
|
||||||
supplier.oldStores.linkMetadata.(*SqlLinkMetadataStore).CreateIndexesIfNotExists()
|
supplier.oldStores.linkMetadata.(*SqlLinkMetadataStore).CreateIndexesIfNotExists()
|
||||||
|
supplier.oldStores.group.(*SqlGroupStore).CreateIndexesIfNotExists()
|
||||||
supplier.CreateIndexesIfNotExistsGroups()
|
|
||||||
|
|
||||||
supplier.oldStores.preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
|
supplier.oldStores.preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user