mirror of
https://github.com/zitadel/zitadel.git
synced 2026-01-04 18:36:52 +00:00
fix(query): user performance (#7081)
* fix(query): user performance (#6537)
* start user by id
* ignore debug bin
* use new user by id
* new sql
* fix(sql): replace STRING with text for psql compatabilit
* some changes
* fix: correct user queries
* fix tests
* unify sql statements
* use specific get user methods
* search login name case insensitive
* refactor: optimise user statements
* add index
* fix queries
* fix: correct domain segregation
* return all login names
* fix queries
* improve readability
* query should be correct now
* cleanup statements
* fix username / loginname handling
* fix: psql doesn't support create view if not exists
* fix: create pre-release
* ignore release comments
* add lower fields
* fix: always to lower
* update to latest projection
---------
Co-authored-by: Livio Spring <livio.a@gmail.com>
(cherry picked from commit ddbea119f1)
* update projection versions
* trigger workflow
---------
Co-authored-by: Silvan <silvan.reusser@gmail.com>
This commit is contained in:
26
cmd/setup/18.go
Normal file
26
cmd/setup/18.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed 18.sql
|
||||
addLowerFieldsToLoginNames string
|
||||
)
|
||||
|
||||
type AddLowerFieldsToLoginNames struct {
|
||||
dbClient *database.DB
|
||||
}
|
||||
|
||||
func (mig *AddLowerFieldsToLoginNames) Execute(ctx context.Context) error {
|
||||
_, err := mig.dbClient.ExecContext(ctx, addLowerFieldsToLoginNames)
|
||||
return err
|
||||
}
|
||||
|
||||
func (mig *AddLowerFieldsToLoginNames) String() string {
|
||||
return "18_add_lower_fields_to_login_names"
|
||||
}
|
||||
6
cmd/setup/18.sql
Normal file
6
cmd/setup/18.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
ALTER TABLE IF EXISTS projections.login_names3_users ADD COLUMN IF NOT EXISTS user_name_lower TEXT GENERATED ALWAYS AS (lower(user_name)) STORED;
|
||||
CREATE INDEX IF NOT EXISTS login_names3_users_search ON projections.login_names3_users (instance_id, user_name_lower) INCLUDE (resource_owner);
|
||||
|
||||
ALTER TABLE IF EXISTS projections.login_names3_domains ADD COLUMN IF NOT EXISTS name_lower TEXT GENERATED ALWAYS AS (lower(name)) STORED;
|
||||
CREATE INDEX IF NOT EXISTS login_names3_domain_search ON projections.login_names3_domains (instance_id, resource_owner, name_lower);
|
||||
CREATE INDEX IF NOT EXISTS login_names3_domain_search_result ON projections.login_names3_domains (instance_id, resource_owner) INCLUDE (is_primary);
|
||||
@@ -75,6 +75,7 @@ type Steps struct {
|
||||
s15CurrentStates *CurrentProjectionState
|
||||
s16UniqueConstraintsLower *UniqueConstraintToLower
|
||||
s17AddOffsetToUniqueConstraints *AddOffsetToCurrentStates
|
||||
s18AddLowerFieldsToLoginNames *AddLowerFieldsToLoginNames
|
||||
}
|
||||
|
||||
type encryptionKeyConfig struct {
|
||||
|
||||
@@ -102,6 +102,7 @@ func Setup(config *Config, steps *Steps, masterKey string) {
|
||||
steps.s15CurrentStates = &CurrentProjectionState{dbClient: zitadelDBClient}
|
||||
steps.s16UniqueConstraintsLower = &UniqueConstraintToLower{dbClient: zitadelDBClient}
|
||||
steps.s17AddOffsetToUniqueConstraints = &AddOffsetToCurrentStates{dbClient: zitadelDBClient}
|
||||
steps.s18AddLowerFieldsToLoginNames = &AddLowerFieldsToLoginNames{dbClient: zitadelDBClient}
|
||||
|
||||
err = projection.Create(ctx, zitadelDBClient, eventstoreClient, config.Projections, nil, nil, nil)
|
||||
logging.OnError(err).Fatal("unable to start projections")
|
||||
@@ -151,6 +152,10 @@ func Setup(config *Config, steps *Steps, masterKey string) {
|
||||
err = migration.Migrate(ctx, eventstoreClient, repeatableStep)
|
||||
logging.OnError(err).Fatalf("unable to migrate repeatable step: %s", repeatableStep.String())
|
||||
}
|
||||
|
||||
// This step is executed after the repeatable steps because it adds fields to the login_names3 projection
|
||||
err = migration.Migrate(ctx, eventstoreClient, steps.s18AddLowerFieldsToLoginNames)
|
||||
logging.WithFields("name", steps.s18AddLowerFieldsToLoginNames.String()).OnError(err).Fatal("migration failed")
|
||||
}
|
||||
|
||||
func readStmt(fs embed.FS, folder, typ, filename string) (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user