fix: reduce (#635)

* fix: management reduce optimization

* fix: reduce optimization

* fix: reduce optimization

* fix: merge master
This commit is contained in:
Fabi 2020-08-26 13:01:37 +02:00 committed by GitHub
parent 87aa97b9c7
commit 4af38b37a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 184 additions and 63 deletions

View File

@ -96,11 +96,8 @@ func (m *IamMember) processUser(event *models.Event) (err error) {
}
for _, member := range members {
m.fillUserData(member, user)
err = m.view.PutIAMMember(member, event.Sequence)
if err != nil {
return err
}
}
return m.view.PutIAMMembers(members, event.Sequence)
default:
return m.view.ProcessedIAMMemberSequence(event.Sequence)
}

View File

@ -32,6 +32,14 @@ func (v *View) PutIAMMember(org *model.IAMMemberView, sequence uint64) error {
return v.ProcessedIAMMemberSequence(sequence)
}
func (v *View) PutIAMMembers(members []*model.IAMMemberView, sequence uint64) error {
err := view.PutIAMMembers(v.Db, iamMemberTable, members...)
if err != nil {
return err
}
return v.ProcessedIAMMemberSequence(sequence)
}
func (v *View) DeleteIAMMember(iamID, userID string, eventSequence uint64) error {
err := view.DeleteIAMMember(v.Db, iamMemberTable, iamID, userID)
if err != nil && !errors.IsNotFound(err) {

View File

@ -148,12 +148,8 @@ func (u *User) fillLoginNamesOnOrgUsers(event *models.Event) error {
}
for _, user := range users {
user.SetLoginNames(policy, org.Domains)
err := u.view.PutUser(user, event.Sequence)
if err != nil {
return err
}
}
return nil
return u.view.PutUsers(users, event.Sequence)
}
func (u *User) fillPreferredLoginNamesOnOrgUsers(event *models.Event) error {
@ -174,12 +170,8 @@ func (u *User) fillPreferredLoginNamesOnOrgUsers(event *models.Event) error {
}
for _, user := range users {
user.PreferredLoginName = user.GenerateLoginName(org.GetPrimaryDomain().Domain, policy.UserLoginMustBeDomain)
err := u.view.PutUser(user, 0)
if err != nil {
return err
}
}
return nil
return u.view.PutUsers(users, 0)
}
func (u *User) OnError(event *models.Event, err error) error {

View File

@ -124,11 +124,8 @@ func (u *UserGrant) processUser(event *models.Event) (err error) {
}
for _, grant := range grants {
u.fillUserData(grant, user)
err = u.view.PutUserGrant(grant, event.Sequence)
if err != nil {
return err
}
}
return u.view.PutUserGrants(grants, event.Sequence)
default:
return u.view.ProcessedUserGrantSequence(event.Sequence)
}
@ -148,8 +145,8 @@ func (u *UserGrant) processProject(event *models.Event) (err error) {
}
for _, grant := range grants {
u.fillProjectData(grant, project)
return u.view.PutUserGrant(grant, event.Sequence)
}
return u.view.PutUserGrants(grants, event.Sequence)
case proj_es_model.ProjectMemberAdded, proj_es_model.ProjectMemberChanged, proj_es_model.ProjectMemberRemoved:
member := new(proj_es_model.ProjectMember)
member.SetData(event)

View File

@ -74,11 +74,12 @@ func (u *UserSession) Reduce(event *models.Event) (err error) {
return u.view.ProcessedUserSessionSequence(event.Sequence)
}
for _, session := range sessions {
if err := u.updateSession(session, event); err != nil {
session.AppendEvent(event)
if err := u.fillUserInfo(session, event.AggregateID); err != nil {
return err
}
}
return nil
return u.view.PutUserSessions(sessions, event.Sequence)
case es_model.UserRemoved:
return u.view.DeleteUserSessions(event.AggregateID, event.Sequence)
default:

View File

@ -55,6 +55,14 @@ func (v *View) PutUser(user *model.UserView, sequence uint64) error {
return v.ProcessedUserSequence(sequence)
}
func (v *View) PutUsers(users []*model.UserView, sequence uint64) error {
err := view.PutUsers(v.Db, userTable, users...)
if err != nil {
return err
}
return v.ProcessedUserSequence(sequence)
}
func (v *View) DeleteUser(userID string, eventSequence uint64) error {
err := view.DeleteUser(v.Db, userTable, userID)
if err != nil {

View File

@ -43,6 +43,14 @@ func (v *View) PutUserGrant(grant *model.UserGrantView, sequence uint64) error {
return v.ProcessedUserGrantSequence(sequence)
}
func (v *View) PutUserGrants(grants []*model.UserGrantView, sequence uint64) error {
err := view.PutUserGrants(v.Db, userGrantTable, grants...)
if err != nil {
return err
}
return v.ProcessedUserGrantSequence(sequence)
}
func (v *View) DeleteUserGrant(grantID string, eventSequence uint64) error {
err := view.DeleteUserGrant(v.Db, userGrantTable, grantID)
if err != nil {

View File

@ -30,6 +30,14 @@ func (v *View) PutUserSession(userSession *model.UserSessionView) error {
return v.ProcessedUserSessionSequence(userSession.Sequence)
}
func (v *View) PutUserSessions(userSession []*model.UserSessionView, sequence uint64) error {
err := view.PutUserSessions(v.Db, userSessionTable, userSession...)
if err != nil {
return err
}
return v.ProcessedUserSessionSequence(sequence)
}
func (v *View) DeleteUserSessions(userID string, eventSequence uint64) error {
err := view.DeleteUserSessions(v.Db, userSessionTable, userID)
if err != nil {

View File

@ -53,6 +53,15 @@ func PutIAMMember(db *gorm.DB, table string, role *model.IAMMemberView) error {
return save(db, role)
}
func PutIAMMembers(db *gorm.DB, table string, members ...*model.IAMMemberView) error {
save := repository.PrepareBulkSave(table)
m := make([]interface{}, len(members))
for i, member := range members {
m[i] = member
}
return save(db, m...)
}
func DeleteIAMMember(db *gorm.DB, table, orgID, userID string) error {
member, err := IAMMemberByIDs(db, table, orgID, userID)
if err != nil {

View File

@ -71,10 +71,10 @@ func (d *OrgDomain) processOrgDomain(event *models.Event) (err error) {
}
for _, existing := range existingDomains {
existing.Primary = false
err := d.view.PutOrgDomain(existing, 0)
if err != nil {
return err
}
}
err = d.view.PutOrgDomains(existingDomains, 0)
if err != nil {
return err
}
err = domain.AppendEvent(event)
case model.OrgDomainRemoved:

View File

@ -99,11 +99,8 @@ func (m *OrgMember) processUser(event *models.Event) (err error) {
}
for _, member := range members {
m.fillUserData(member, user)
err = m.view.PutOrgMember(member, event.Sequence)
if err != nil {
return err
}
}
return m.view.PutOrgMembers(members, event.Sequence)
default:
return m.view.ProcessedOrgMemberSequence(event.Sequence)
}

View File

@ -47,7 +47,7 @@ func (p *ProjectGrant) Reduce(event *models.Event) (err error) {
if err != nil {
return err
}
return p.updateExistingProjects(project)
return p.updateExistingProjects(project, event.Sequence)
case es_model.ProjectGrantAdded:
err = grantedProject.AppendEvent(event)
if err != nil {
@ -106,21 +106,15 @@ func (p *ProjectGrant) getProject(projectID string) (*proj_model.Project, error)
return p.projectEvents.ProjectByID(context.Background(), projectID)
}
func (p *ProjectGrant) updateExistingProjects(project *view_model.ProjectView) error {
func (p *ProjectGrant) updateExistingProjects(project *view_model.ProjectView, sequence uint64) error {
projectGrants, err := p.view.ProjectGrantsByProjectID(project.ProjectID)
if err != nil {
logging.LogWithFields("SPOOL-los03", "id", project.ProjectID).WithError(err).Warn("could not update existing projects")
}
for _, existing := range projectGrants {
existing.Name = project.Name
err := p.view.PutProjectGrant(existing)
if err != nil {
logging.LogWithFields("SPOOL-sjwi3", "id", existing.ProjectID).WithError(err).Warn("could not update existing project")
return err
}
}
return p.view.ProcessedProjectGrantSequence(project.Sequence)
return p.view.PutProjectGrants(projectGrants, sequence)
}
func (p *ProjectGrant) OnError(event *models.Event, err error) error {

View File

@ -101,11 +101,8 @@ func (p *ProjectGrantMember) processUser(event *models.Event) (err error) {
}
for _, member := range members {
p.fillUserData(member, user)
err = p.view.PutProjectGrantMember(member, event.Sequence)
if err != nil {
return err
}
}
return p.view.PutProjectGrantMembers(members, event.Sequence)
default:
return p.view.ProcessedProjectGrantMemberSequence(event.Sequence)
}

View File

@ -101,11 +101,8 @@ func (p *ProjectMember) processUser(event *models.Event) (err error) {
}
for _, member := range members {
p.fillUserData(member, user)
err = p.view.PutProjectMember(member, event.Sequence)
if err != nil {
return err
}
}
return p.view.PutProjectMembers(members, event.Sequence)
default:
return p.view.ProcessedProjectMemberSequence(event.Sequence)
}

View File

@ -106,11 +106,8 @@ func (u *UserGrant) processUser(event *models.Event) (err error) {
}
for _, grant := range grants {
u.fillUserData(grant, user)
err = u.view.PutUserGrant(grant, event.Sequence)
if err != nil {
return err
}
}
return u.view.PutUserGrants(grants, event.Sequence)
default:
return u.view.ProcessedUserGrantSequence(event.Sequence)
}
@ -133,8 +130,8 @@ func (u *UserGrant) processProject(event *models.Event) (err error) {
}
for _, grant := range grants {
u.fillProjectData(grant, project)
return u.view.PutUserGrant(grant, event.Sequence)
}
return u.view.PutUserGrants(grants, event.Sequence)
default:
return u.view.ProcessedUserGrantSequence(event.Sequence)
}

View File

@ -38,6 +38,14 @@ func (v *View) PutOrgDomain(org *model.OrgDomainView, sequence uint64) error {
return nil
}
func (v *View) PutOrgDomains(domains []*model.OrgDomainView, sequence uint64) error {
err := view.PutOrgDomains(v.Db, orgDomainTable, domains...)
if err != nil {
return err
}
return v.ProcessedUserSequence(sequence)
}
func (v *View) DeleteOrgDomain(orgID, domain string, eventSequence uint64) error {
err := view.DeleteOrgDomain(v.Db, orgDomainTable, orgID, domain)
if err != nil {

View File

@ -23,8 +23,16 @@ func (v *View) OrgMembersByUserID(userID string) ([]*model.OrgMemberView, error)
return view.OrgMembersByUserID(v.Db, orgMemberTable, userID)
}
func (v *View) PutOrgMember(org *model.OrgMemberView, sequence uint64) error {
err := view.PutOrgMember(v.Db, orgMemberTable, org)
func (v *View) PutOrgMember(member *model.OrgMemberView, sequence uint64) error {
err := view.PutOrgMember(v.Db, orgMemberTable, member)
if err != nil {
return err
}
return v.ProcessedOrgMemberSequence(sequence)
}
func (v *View) PutOrgMembers(members []*model.OrgMemberView, sequence uint64) error {
err := view.PutOrgMembers(v.Db, orgMemberTable, members...)
if err != nil {
return err
}

View File

@ -31,12 +31,20 @@ func (v *View) SearchProjectGrants(request *proj_model.ProjectGrantViewSearchReq
return view.SearchProjectGrants(v.Db, grantedProjectTable, request)
}
func (v *View) PutProjectGrant(project *model.ProjectGrantView) error {
err := view.PutProjectGrant(v.Db, grantedProjectTable, project)
func (v *View) PutProjectGrant(grant *model.ProjectGrantView) error {
err := view.PutProjectGrant(v.Db, grantedProjectTable, grant)
if err != nil {
return err
}
return v.ProcessedProjectGrantSequence(project.Sequence)
return v.ProcessedProjectGrantSequence(grant.Sequence)
}
func (v *View) PutProjectGrants(grants []*model.ProjectGrantView, sequence uint64) error {
err := view.PutProjectGrants(v.Db, grantedProjectTable, grants...)
if err != nil {
return err
}
return v.ProcessedProjectGrantSequence(sequence)
}
func (v *View) DeleteProjectGrant(grantID string, eventSequence uint64) error {

View File

@ -27,8 +27,16 @@ func (v *View) ProjectGrantMembersByUserID(userID string) ([]*model.ProjectGrant
return view.ProjectGrantMembersByUserID(v.Db, projectGrantMemberTable, userID)
}
func (v *View) PutProjectGrantMember(project *model.ProjectGrantMemberView, sequence uint64) error {
err := view.PutProjectGrantMember(v.Db, projectGrantMemberTable, project)
func (v *View) PutProjectGrantMember(member *model.ProjectGrantMemberView, sequence uint64) error {
err := view.PutProjectGrantMember(v.Db, projectGrantMemberTable, member)
if err != nil {
return err
}
return v.ProcessedProjectGrantMemberSequence(sequence)
}
func (v *View) PutProjectGrantMembers(members []*model.ProjectGrantMemberView, sequence uint64) error {
err := view.PutProjectGrantMembers(v.Db, projectGrantMemberTable, members...)
if err != nil {
return err
}

View File

@ -35,6 +35,14 @@ func (v *View) PutProjectMember(project *model.ProjectMemberView, sequence uint6
return v.ProcessedProjectMemberSequence(sequence)
}
func (v *View) PutProjectMembers(project []*model.ProjectMemberView, sequence uint64) error {
err := view.PutProjectMembers(v.Db, projectMemberTable, project...)
if err != nil {
return err
}
return v.ProcessedProjectMemberSequence(sequence)
}
func (v *View) DeleteProjectMember(projectID, userID string, eventSequence uint64) error {
err := view.DeleteProjectMember(v.Db, projectMemberTable, projectID, userID)
if err != nil {

View File

@ -47,6 +47,14 @@ func (v *View) PutUserGrant(grant *model.UserGrantView, sequence uint64) error {
return v.ProcessedUserGrantSequence(sequence)
}
func (v *View) PutUserGrants(grants []*model.UserGrantView, sequence uint64) error {
err := view.PutUserGrants(v.Db, userGrantTable, grants...)
if err != nil {
return err
}
return v.ProcessedUserGrantSequence(sequence)
}
func (v *View) DeleteUserGrant(grantID string, eventSequence uint64) error {
err := view.DeleteUserGrant(v.Db, userGrantTable, grantID)
if err != nil {

View File

@ -60,9 +60,18 @@ func OrgDomainsByOrgID(db *gorm.DB, table string, orgID string) ([]*model.OrgDom
return domains, nil
}
func PutOrgDomain(db *gorm.DB, table string, role *model.OrgDomainView) error {
func PutOrgDomain(db *gorm.DB, table string, domain *model.OrgDomainView) error {
save := repository.PrepareSave(table)
return save(db, role)
return save(db, domain)
}
func PutOrgDomains(db *gorm.DB, table string, domains ...*model.OrgDomainView) error {
save := repository.PrepareBulkSave(table)
d := make([]interface{}, len(domains))
for i, domain := range domains {
d[i] = domain
}
return save(db, d...)
}
func DeleteOrgDomain(db *gorm.DB, table, orgID, domain string) error {

View File

@ -53,6 +53,15 @@ func PutOrgMember(db *gorm.DB, table string, role *model.OrgMemberView) error {
return save(db, role)
}
func PutOrgMembers(db *gorm.DB, table string, members ...*model.OrgMemberView) error {
save := repository.PrepareBulkSave(table)
m := make([]interface{}, len(members))
for i, member := range members {
m[i] = member
}
return save(db, m...)
}
func DeleteOrgMember(db *gorm.DB, table, orgID, userID string) error {
member, err := OrgMemberByIDs(db, table, orgID, userID)
if err != nil {

View File

@ -63,6 +63,15 @@ func PutProjectGrantMember(db *gorm.DB, table string, role *model.ProjectGrantMe
return save(db, role)
}
func PutProjectGrantMembers(db *gorm.DB, table string, members ...*model.ProjectGrantMemberView) error {
save := repository.PrepareBulkSave(table)
m := make([]interface{}, len(members))
for i, member := range members {
m[i] = member
}
return save(db, m...)
}
func DeleteProjectGrantMember(db *gorm.DB, table, grantID, userID string) error {
grant, err := ProjectGrantMemberByIDs(db, table, grantID, userID)
if err != nil {

View File

@ -63,9 +63,18 @@ func SearchProjectGrants(db *gorm.DB, table string, req *proj_model.ProjectGrant
return projectGrants, count, err
}
func PutProjectGrant(db *gorm.DB, table string, project *model.ProjectGrantView) error {
func PutProjectGrant(db *gorm.DB, table string, grant *model.ProjectGrantView) error {
save := repository.PrepareSave(table)
return save(db, project)
return save(db, grant)
}
func PutProjectGrants(db *gorm.DB, table string, grants ...*model.ProjectGrantView) error {
save := repository.PrepareBulkSave(table)
g := make([]interface{}, len(grants))
for i, grant := range grants {
g[i] = grant
}
return save(db, g...)
}
func DeleteProjectGrant(db *gorm.DB, table, grantID string) error {

View File

@ -62,6 +62,15 @@ func PutProjectMember(db *gorm.DB, table string, role *model.ProjectMemberView)
return save(db, role)
}
func PutProjectMembers(db *gorm.DB, table string, members ...*model.ProjectMemberView) error {
save := repository.PrepareBulkSave(table)
m := make([]interface{}, len(members))
for i, member := range members {
m[i] = member
}
return save(db, m...)
}
func DeleteProjectMember(db *gorm.DB, table, projectID, userID string) error {
role, err := ProjectMemberByIDs(db, table, projectID, userID)
if err != nil {

View File

@ -11,4 +11,4 @@ and not
s.Rect(currX, currY, qs.blockSize, qs.blockSize, "fill:black;stroke:none")
```
This allows the svg to be styled by css more easily and does not compromise Content Security Policy (CSP).
This allows the svg to be styled by css more easily and does not compromise Content Security Policy (CSP).

View File

@ -63,6 +63,15 @@ func PutUserSession(db *gorm.DB, table string, session *model.UserSessionView) e
return save(db, session)
}
func PutUserSessions(db *gorm.DB, table string, sessions ...*model.UserSessionView) error {
save := repository.PrepareBulkSave(table)
s := make([]interface{}, len(sessions))
for i, session := range sessions {
s[i] = session
}
return save(db, s...)
}
func DeleteUserSessions(db *gorm.DB, table, userID string) error {
delete := repository.PrepareDeleteByKey(table, model.UserSessionSearchKey(usr_model.UserSessionSearchKeyUserID), userID)
return delete(db)

View File

@ -129,6 +129,15 @@ func PutUserGrant(db *gorm.DB, table string, grant *model.UserGrantView) error {
return save(db, grant)
}
func PutUserGrants(db *gorm.DB, table string, grants ...*model.UserGrantView) error {
save := repository.PrepareBulkSave(table)
g := make([]interface{}, len(grants))
for i, grant := range grants {
g[i] = grant
}
return save(db, g...)
}
func DeleteUserGrant(db *gorm.DB, table, grantID string) error {
delete := repository.PrepareDeleteByKey(table, model.UserGrantSearchKey(grant_model.UserGrantSearchKeyGrantID), grantID)
return delete(db)