From 5c99bdf14f2be27d14880615d43ab8ca46188e02 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Mon, 30 Jan 2023 15:41:30 +0800 Subject: [PATCH] 1 --- pkg/common/db/controller/group.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/common/db/controller/group.go b/pkg/common/db/controller/group.go index 176cbafd1..295698d93 100644 --- a/pkg/common/db/controller/group.go +++ b/pkg/common/db/controller/group.go @@ -158,13 +158,15 @@ func (g *GroupDataBase) FindGroupsByID(ctx context.Context, groupIDs []string) ( return g.cache.GetGroupsInfo(ctx, groupIDs) } -func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relation.Group, groupMember []*relation.GroupMember) error { +func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relation.Group, groupMembers []*relation.GroupMember) error { return g.db.Transaction(func(tx *gorm.DB) error { - if err := g.groupDB.Create(ctx, groups, tx); err != nil { - return err + if len(groups) > 0 { + if err := g.groupDB.Create(ctx, groups, tx); err != nil { + return err + } } - if len(groupMember) > 0 { - if err := g.groupMemberDB.Create(ctx, groupMember, tx); err != nil { + if len(groupMembers) > 0 { + if err := g.groupMemberDB.Create(ctx, groupMembers, tx); err != nil { return err } }