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:
Silvan
2023-02-27 22:36:43 +01:00
committed by GitHub
parent 80003939ad
commit e38abdcdf3
170 changed files with 3101 additions and 3169 deletions

View File

@@ -8,6 +8,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/errors"
"github.com/zitadel/zitadel/internal/query/projection"
"github.com/zitadel/zitadel/internal/telemetry/tracing"
@@ -95,7 +96,7 @@ func (q *Queries) SearchProjectRoles(ctx context.Context, shouldTriggerBulk bool
eq[ProjectRoleColumnOwnerRemoved.identifier()] = false
}
query, scan := prepareProjectRolesQuery()
query, scan := prepareProjectRolesQuery(ctx, q.client)
stmt, args, err := queries.toQuery(query).Where(eq).ToSql()
if err != nil {
return nil, errors.ThrowInvalidArgument(err, "QUERY-3N9ff", "Errors.Query.InvalidRequest")
@@ -131,7 +132,7 @@ func (q *Queries) SearchGrantedProjectRoles(ctx context.Context, grantID, grante
eq[ProjectRoleColumnOwnerRemoved.identifier()] = false
}
query, scan := prepareProjectRolesQuery()
query, scan := prepareProjectRolesQuery(ctx, q.client)
stmt, args, err := queries.toQuery(query).Where(eq).ToSql()
if err != nil {
return nil, errors.ThrowInvalidArgument(err, "QUERY-3N9ff", "Errors.Query.InvalidRequest")
@@ -212,7 +213,7 @@ func (q *ProjectRoleSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuil
return query
}
func prepareProjectRolesQuery() (sq.SelectBuilder, func(*sql.Rows) (*ProjectRoles, error)) {
func prepareProjectRolesQuery(ctx context.Context, db prepareDatabase) (sq.SelectBuilder, func(*sql.Rows) (*ProjectRoles, error)) {
return sq.Select(
ProjectRoleColumnProjectID.identifier(),
ProjectRoleColumnCreationDate.identifier(),
@@ -223,7 +224,8 @@ func prepareProjectRolesQuery() (sq.SelectBuilder, func(*sql.Rows) (*ProjectRole
ProjectRoleColumnDisplayName.identifier(),
ProjectRoleColumnGroupName.identifier(),
countColumn.identifier()).
From(projectRolesTable.identifier()).PlaceholderFormat(sq.Dollar),
From(projectRolesTable.identifier() + db.Timetravel(call.Took(ctx))).
PlaceholderFormat(sq.Dollar),
func(rows *sql.Rows) (*ProjectRoles, error) {
projects := make([]*ProjectRole, 0)
var count uint64