mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-23 13:28:45 +00:00
perf: query data AS OF SYSTEM TIME (#5231)
Queries the data in the storage layser at the timestamp when the call hit the API layer
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/api/call"
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
@@ -225,7 +226,7 @@ func (q *Queries) UserGrant(ctx context.Context, shouldTriggerBulk bool, withOwn
|
||||
projection.UserGrantProjection.Trigger(ctx)
|
||||
}
|
||||
|
||||
query, scan := prepareUserGrantQuery()
|
||||
query, scan := prepareUserGrantQuery(ctx, q.client)
|
||||
for _, q := range queries {
|
||||
query = q.toQuery(query)
|
||||
}
|
||||
@@ -246,7 +247,7 @@ func (q *Queries) UserGrants(ctx context.Context, queries *UserGrantsQueries, wi
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
query, scan := prepareUserGrantsQuery()
|
||||
query, scan := prepareUserGrantsQuery(ctx, q.client)
|
||||
eq := sq.Eq{UserGrantInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()}
|
||||
if !withOwnerRemoved {
|
||||
addUserGrantWithoutOwnerRemoved(eq)
|
||||
@@ -274,7 +275,7 @@ func (q *Queries) UserGrants(ctx context.Context, queries *UserGrantsQueries, wi
|
||||
return grants, nil
|
||||
}
|
||||
|
||||
func prepareUserGrantQuery() (sq.SelectBuilder, func(*sql.Row) (*UserGrant, error)) {
|
||||
func prepareUserGrantQuery(ctx context.Context, db prepareDatabase) (sq.SelectBuilder, func(*sql.Row) (*UserGrant, error)) {
|
||||
return sq.Select(
|
||||
UserGrantID.identifier(),
|
||||
UserGrantCreationDate.identifier(),
|
||||
@@ -307,7 +308,7 @@ func prepareUserGrantQuery() (sq.SelectBuilder, func(*sql.Row) (*UserGrant, erro
|
||||
LeftJoin(join(HumanUserIDCol, UserGrantUserID)).
|
||||
LeftJoin(join(OrgColumnID, UserGrantResourceOwner)).
|
||||
LeftJoin(join(ProjectColumnID, UserGrantProjectID)).
|
||||
LeftJoin(join(LoginNameUserIDCol, UserGrantUserID)).
|
||||
LeftJoin(join(LoginNameUserIDCol, UserGrantUserID) + db.Timetravel(call.Took(ctx))).
|
||||
Where(
|
||||
sq.Eq{LoginNameIsPrimaryCol.identifier(): true},
|
||||
).PlaceholderFormat(sq.Dollar),
|
||||
@@ -382,7 +383,7 @@ func prepareUserGrantQuery() (sq.SelectBuilder, func(*sql.Row) (*UserGrant, erro
|
||||
}
|
||||
}
|
||||
|
||||
func prepareUserGrantsQuery() (sq.SelectBuilder, func(*sql.Rows) (*UserGrants, error)) {
|
||||
func prepareUserGrantsQuery(ctx context.Context, db prepareDatabase) (sq.SelectBuilder, func(*sql.Rows) (*UserGrants, error)) {
|
||||
return sq.Select(
|
||||
UserGrantID.identifier(),
|
||||
UserGrantCreationDate.identifier(),
|
||||
@@ -417,7 +418,7 @@ func prepareUserGrantsQuery() (sq.SelectBuilder, func(*sql.Rows) (*UserGrants, e
|
||||
LeftJoin(join(HumanUserIDCol, UserGrantUserID)).
|
||||
LeftJoin(join(OrgColumnID, UserGrantResourceOwner)).
|
||||
LeftJoin(join(ProjectColumnID, UserGrantProjectID)).
|
||||
LeftJoin(join(LoginNameUserIDCol, UserGrantUserID)).
|
||||
LeftJoin(join(LoginNameUserIDCol, UserGrantUserID) + db.Timetravel(call.Took(ctx))).
|
||||
Where(
|
||||
sq.Eq{LoginNameIsPrimaryCol.identifier(): true},
|
||||
).PlaceholderFormat(sq.Dollar),
|
||||
|
||||
Reference in New Issue
Block a user