mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 07:57:32 +00:00
feat(eventstore): increase parallel write capabilities (#5940)
This implementation increases parallel write capabilities of the eventstore. Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and [06](https://zitadel.com/docs/support/advisory/a10006). The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`. If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
This commit is contained in:
@@ -144,76 +144,6 @@ func UsersByOrgID(db *gorm.DB, table, orgID, instanceID string) ([]*model.UserVi
|
||||
return users, err
|
||||
}
|
||||
|
||||
func UserIDsByDomain(db *gorm.DB, table, orgDomain, instanceID string) ([]string, error) {
|
||||
type id struct {
|
||||
Id string
|
||||
}
|
||||
ids := make([]id, 0)
|
||||
orgIDQuery := &usr_model.UserSearchQuery{
|
||||
Key: usr_model.UserSearchKeyUserName,
|
||||
Method: domain.SearchMethodEndsWithIgnoreCase,
|
||||
Value: "%" + orgDomain,
|
||||
}
|
||||
instanceIDQuery := &usr_model.UserSearchQuery{
|
||||
Key: usr_model.UserSearchKeyInstanceID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: instanceID,
|
||||
}
|
||||
ownerRemovedQuery := &usr_model.UserSearchQuery{
|
||||
Key: usr_model.UserSearchOwnerRemoved,
|
||||
Method: domain.SearchMethodEquals,
|
||||
Value: false,
|
||||
}
|
||||
query := repository.PrepareSearchQuery(table, model.UserSearchRequest{
|
||||
Queries: []*usr_model.UserSearchQuery{orgIDQuery, instanceIDQuery, ownerRemovedQuery},
|
||||
})
|
||||
_, err := query(db, &ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
users := make([]string, len(ids))
|
||||
for i, id := range ids {
|
||||
users[i] = id.Id
|
||||
}
|
||||
return users, err
|
||||
}
|
||||
|
||||
func SearchUsers(db *gorm.DB, table string, req *usr_model.UserSearchRequest) ([]*model.UserView, uint64, error) {
|
||||
users := make([]*model.UserView, 0)
|
||||
query := repository.PrepareSearchQuery(table, model.UserSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
|
||||
count, err := query(db, &users)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return users, count, nil
|
||||
}
|
||||
|
||||
func GetGlobalUserByLoginName(db *gorm.DB, table, loginName, instanceID string) (*model.UserView, error) {
|
||||
user := new(model.UserView)
|
||||
query := repository.PrepareGetByQuery(table,
|
||||
&model.UserSearchQuery{Key: usr_model.UserSearchKeyLoginNames, Value: loginName, Method: domain.SearchMethodListContains},
|
||||
&model.UserSearchQuery{Key: usr_model.UserSearchKeyInstanceID, Value: instanceID, Method: domain.SearchMethodEquals},
|
||||
&model.UserSearchQuery{Key: usr_model.UserSearchOwnerRemoved, Value: false, Method: domain.SearchMethodEquals},
|
||||
)
|
||||
err := query(db, user)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-8uWer", "Errors.User.NotFound")
|
||||
}
|
||||
user.SetEmptyUserType()
|
||||
return user, err
|
||||
}
|
||||
|
||||
func UserMFAs(db *gorm.DB, table, userID, instanceID string) ([]*usr_model.MultiFactor, error) {
|
||||
user, err := UserByID(db, table, userID, instanceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user.OTPState == int32(usr_model.MFAStateUnspecified) {
|
||||
return []*usr_model.MultiFactor{}, nil
|
||||
}
|
||||
return []*usr_model.MultiFactor{{Type: usr_model.MFATypeOTP, State: usr_model.MFAState(user.OTPState)}}, nil
|
||||
}
|
||||
|
||||
func PutUsers(db *gorm.DB, table string, users ...*model.UserView) error {
|
||||
save := repository.PrepareBulkSave(table)
|
||||
u := make([]interface{}, len(users))
|
||||
|
Reference in New Issue
Block a user