mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
fb162a7d75
# Which Problems Are Solved During the implementation of #7486 it was noticed, that projections in the `auth` database schema could be blocked. Investigations suggested, that this is due to the use of [GORM](https://gorm.io/index.html) and it's inability to use an existing (sql) transaction. With the improved / simplified handling (see below) there should also be a minimal improvement in performance, resp. reduced database update statements. # How the Problems Are Solved The handlers in `auth` are exchanged to proper (sql) statements and gorm usage is removed for any writing part. To further improve / simplify the handling of the users, a new `auth.users3` table is created, where only attributes are handled, which are not yet available from the `projections.users`, `projections.login_name` and `projections.user_auth_methods` do not provide. This reduces the events handled in that specific handler by a lot. # Additional Changes None # Additional Context relates to #7486
51 lines
2.0 KiB
Go
51 lines
2.0 KiB
Go
package view
|
|
|
|
import (
|
|
"github.com/jinzhu/gorm"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/user/model"
|
|
usr_model "github.com/zitadel/zitadel/internal/user/repository/view/model"
|
|
"github.com/zitadel/zitadel/internal/view/repository"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
func RefreshTokenByID(db *gorm.DB, table, tokenID, instanceID string) (*usr_model.RefreshTokenView, error) {
|
|
token := new(usr_model.RefreshTokenView)
|
|
query := repository.PrepareGetByQuery(table,
|
|
&usr_model.RefreshTokenSearchQuery{Key: model.RefreshTokenSearchKeyRefreshTokenID, Method: domain.SearchMethodEquals, Value: tokenID},
|
|
&usr_model.RefreshTokenSearchQuery{Key: model.RefreshTokenSearchKeyInstanceID, Method: domain.SearchMethodEquals, Value: instanceID},
|
|
)
|
|
err := query(db, token)
|
|
if zerrors.IsNotFound(err) {
|
|
return nil, zerrors.ThrowNotFound(nil, "VIEW-6ub3p", "Errors.RefreshToken.NotFound")
|
|
}
|
|
return token, err
|
|
}
|
|
|
|
func RefreshTokensByUserID(db *gorm.DB, table, userID, instanceID string) ([]*usr_model.RefreshTokenView, error) {
|
|
tokens := make([]*usr_model.RefreshTokenView, 0)
|
|
userIDQuery := &model.RefreshTokenSearchQuery{
|
|
Key: model.RefreshTokenSearchKeyUserID,
|
|
Method: domain.SearchMethodEquals,
|
|
Value: userID,
|
|
}
|
|
instanceIDQuery := &model.RefreshTokenSearchQuery{
|
|
Key: model.RefreshTokenSearchKeyInstanceID,
|
|
Method: domain.SearchMethodEquals,
|
|
Value: instanceID,
|
|
}
|
|
query := repository.PrepareSearchQuery(table, usr_model.RefreshTokenSearchRequest{
|
|
Queries: []*model.RefreshTokenSearchQuery{userIDQuery, instanceIDQuery},
|
|
})
|
|
_, err := query(db, &tokens)
|
|
return tokens, err
|
|
}
|
|
|
|
func SearchRefreshTokens(db *gorm.DB, table string, req *model.RefreshTokenSearchRequest) ([]*usr_model.RefreshTokenView, uint64, error) {
|
|
tokens := make([]*usr_model.RefreshTokenView, 0)
|
|
query := repository.PrepareSearchQuery(table, usr_model.RefreshTokenSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
|
|
count, err := query(db, &tokens)
|
|
return tokens, count, err
|
|
}
|