mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +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:
@@ -26,6 +26,62 @@ var (
|
||||
"has_project_check",
|
||||
"private_labeling_setting",
|
||||
}
|
||||
|
||||
prepareProjectsStmt = `SELECT projections.projects3.id,` +
|
||||
` projections.projects3.creation_date,` +
|
||||
` projections.projects3.change_date,` +
|
||||
` projections.projects3.resource_owner,` +
|
||||
` projections.projects3.state,` +
|
||||
` projections.projects3.sequence,` +
|
||||
` projections.projects3.name,` +
|
||||
` projections.projects3.project_role_assertion,` +
|
||||
` projections.projects3.project_role_check,` +
|
||||
` projections.projects3.has_project_check,` +
|
||||
` projections.projects3.private_labeling_setting,` +
|
||||
` COUNT(*) OVER ()` +
|
||||
` FROM projections.projects3` +
|
||||
` AS OF SYSTEM TIME '-1 ms'`
|
||||
prepareProjectsCols = []string{
|
||||
"id",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"state",
|
||||
"sequence",
|
||||
"name",
|
||||
"project_role_assertion",
|
||||
"project_role_check",
|
||||
"has_project_check",
|
||||
"private_labeling_setting",
|
||||
"count",
|
||||
}
|
||||
|
||||
prepareProjectStmt = `SELECT projections.projects3.id,` +
|
||||
` projections.projects3.creation_date,` +
|
||||
` projections.projects3.change_date,` +
|
||||
` projections.projects3.resource_owner,` +
|
||||
` projections.projects3.state,` +
|
||||
` projections.projects3.sequence,` +
|
||||
` projections.projects3.name,` +
|
||||
` projections.projects3.project_role_assertion,` +
|
||||
` projections.projects3.project_role_check,` +
|
||||
` projections.projects3.has_project_check,` +
|
||||
` projections.projects3.private_labeling_setting` +
|
||||
` FROM projections.projects3` +
|
||||
` AS OF SYSTEM TIME '-1 ms'`
|
||||
prepareProjectCols = []string{
|
||||
"id",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"state",
|
||||
"sequence",
|
||||
"name",
|
||||
"project_role_assertion",
|
||||
"project_role_check",
|
||||
"has_project_check",
|
||||
"private_labeling_setting",
|
||||
}
|
||||
)
|
||||
|
||||
func Test_ProjectPrepares(t *testing.T) {
|
||||
@@ -44,19 +100,7 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT projections.projects3.id,`+
|
||||
` projections.projects3.creation_date,`+
|
||||
` projections.projects3.change_date,`+
|
||||
` projections.projects3.resource_owner,`+
|
||||
` projections.projects3.state,`+
|
||||
` projections.projects3.sequence,`+
|
||||
` projections.projects3.name,`+
|
||||
` projections.projects3.project_role_assertion,`+
|
||||
` projections.projects3.project_role_check,`+
|
||||
` projections.projects3.has_project_check,`+
|
||||
` projections.projects3.private_labeling_setting,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.projects3`),
|
||||
regexp.QuoteMeta(prepareProjectsStmt),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -68,33 +112,8 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT projections.projects3.id,`+
|
||||
` projections.projects3.creation_date,`+
|
||||
` projections.projects3.change_date,`+
|
||||
` projections.projects3.resource_owner,`+
|
||||
` projections.projects3.state,`+
|
||||
` projections.projects3.sequence,`+
|
||||
` projections.projects3.name,`+
|
||||
` projections.projects3.project_role_assertion,`+
|
||||
` projections.projects3.project_role_check,`+
|
||||
` projections.projects3.has_project_check,`+
|
||||
` projections.projects3.private_labeling_setting,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.projects3`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"state",
|
||||
"sequence",
|
||||
"name",
|
||||
"project_role_assertion",
|
||||
"project_role_check",
|
||||
"has_project_check",
|
||||
"private_labeling_setting",
|
||||
"count",
|
||||
},
|
||||
regexp.QuoteMeta(prepareProjectsStmt),
|
||||
prepareProjectsCols,
|
||||
[][]driver.Value{
|
||||
{
|
||||
"id",
|
||||
@@ -138,33 +157,8 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT projections.projects3.id,`+
|
||||
` projections.projects3.creation_date,`+
|
||||
` projections.projects3.change_date,`+
|
||||
` projections.projects3.resource_owner,`+
|
||||
` projections.projects3.state,`+
|
||||
` projections.projects3.sequence,`+
|
||||
` projections.projects3.name,`+
|
||||
` projections.projects3.project_role_assertion,`+
|
||||
` projections.projects3.project_role_check,`+
|
||||
` projections.projects3.has_project_check,`+
|
||||
` projections.projects3.private_labeling_setting,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.projects3`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"state",
|
||||
"sequence",
|
||||
"name",
|
||||
"project_role_assertion",
|
||||
"project_role_check",
|
||||
"has_project_check",
|
||||
"private_labeling_setting",
|
||||
"count",
|
||||
},
|
||||
regexp.QuoteMeta(prepareProjectsStmt),
|
||||
prepareProjectsCols,
|
||||
[][]driver.Value{
|
||||
{
|
||||
"id-1",
|
||||
@@ -234,19 +228,7 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectsQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT projections.projects3.id,`+
|
||||
` projections.projects3.creation_date,`+
|
||||
` projections.projects3.change_date,`+
|
||||
` projections.projects3.resource_owner,`+
|
||||
` projections.projects3.state,`+
|
||||
` projections.projects3.sequence,`+
|
||||
` projections.projects3.name,`+
|
||||
` projections.projects3.project_role_assertion,`+
|
||||
` projections.projects3.project_role_check,`+
|
||||
` projections.projects3.has_project_check,`+
|
||||
` projections.projects3.private_labeling_setting,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.projects3`),
|
||||
regexp.QuoteMeta(prepareProjectsStmt),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -263,18 +245,7 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
`SELECT projections.projects3.id,`+
|
||||
` projections.projects3.creation_date,`+
|
||||
` projections.projects3.change_date,`+
|
||||
` projections.projects3.resource_owner,`+
|
||||
` projections.projects3.state,`+
|
||||
` projections.projects3.sequence,`+
|
||||
` projections.projects3.name,`+
|
||||
` projections.projects3.project_role_assertion,`+
|
||||
` projections.projects3.project_role_check,`+
|
||||
` projections.projects3.has_project_check,`+
|
||||
` projections.projects3.private_labeling_setting`+
|
||||
` FROM projections.projects3`,
|
||||
prepareProjectStmt,
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -292,31 +263,8 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT projections.projects3.id,`+
|
||||
` projections.projects3.creation_date,`+
|
||||
` projections.projects3.change_date,`+
|
||||
` projections.projects3.resource_owner,`+
|
||||
` projections.projects3.state,`+
|
||||
` projections.projects3.sequence,`+
|
||||
` projections.projects3.name,`+
|
||||
` projections.projects3.project_role_assertion,`+
|
||||
` projections.projects3.project_role_check,`+
|
||||
` projections.projects3.has_project_check,`+
|
||||
` projections.projects3.private_labeling_setting`+
|
||||
` FROM projections.projects3`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"state",
|
||||
"sequence",
|
||||
"name",
|
||||
"project_role_assertion",
|
||||
"project_role_check",
|
||||
"has_project_check",
|
||||
"private_labeling_setting",
|
||||
},
|
||||
regexp.QuoteMeta(prepareProjectStmt),
|
||||
prepareProjectCols,
|
||||
[]driver.Value{
|
||||
"id",
|
||||
testNow,
|
||||
@@ -351,18 +299,7 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
prepare: prepareProjectQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT projections.projects3.id,`+
|
||||
` projections.projects3.creation_date,`+
|
||||
` projections.projects3.change_date,`+
|
||||
` projections.projects3.resource_owner,`+
|
||||
` projections.projects3.state,`+
|
||||
` projections.projects3.sequence,`+
|
||||
` projections.projects3.name,`+
|
||||
` projections.projects3.project_role_assertion,`+
|
||||
` projections.projects3.project_role_check,`+
|
||||
` projections.projects3.has_project_check,`+
|
||||
` projections.projects3.private_labeling_setting`+
|
||||
` FROM projections.projects3`),
|
||||
regexp.QuoteMeta(prepareProjectStmt),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -377,7 +314,7 @@ func Test_ProjectPrepares(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assertPrepare(t, tt.prepare, tt.object, tt.want.sqlExpectations, tt.want.err)
|
||||
assertPrepare(t, tt.prepare, tt.object, tt.want.sqlExpectations, tt.want.err, defaultPrepareArgs...)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user