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

@@ -13,6 +13,31 @@ import (
errs "github.com/zitadel/zitadel/internal/errors"
)
var (
prepareCustomTextsStmt = `SELECT projections.custom_texts2.aggregate_id,` +
` projections.custom_texts2.sequence,` +
` projections.custom_texts2.creation_date,` +
` projections.custom_texts2.change_date,` +
` projections.custom_texts2.language,` +
` projections.custom_texts2.template,` +
` projections.custom_texts2.key,` +
` projections.custom_texts2.text,` +
` COUNT(*) OVER ()` +
` FROM projections.custom_texts2` +
` AS OF SYSTEM TIME '-1 ms'`
prepareCustomTextsCols = []string{
"aggregate_id",
"sequence",
"creation_date",
"change_date",
"language",
"template",
"key",
"text",
"count",
}
)
func Test_CustomTextPrepares(t *testing.T) {
type want struct {
sqlExpectations sqlExpectation
@@ -29,16 +54,7 @@ func Test_CustomTextPrepares(t *testing.T) {
prepare: prepareCustomTextsQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.custom_texts2.aggregate_id,`+
` projections.custom_texts2.sequence,`+
` projections.custom_texts2.creation_date,`+
` projections.custom_texts2.change_date,`+
` projections.custom_texts2.language,`+
` projections.custom_texts2.template,`+
` projections.custom_texts2.key,`+
` projections.custom_texts2.text,`+
` COUNT(*) OVER ()`+
` FROM projections.custom_texts2`),
regexp.QuoteMeta(prepareCustomTextsStmt),
nil,
nil,
),
@@ -56,27 +72,8 @@ func Test_CustomTextPrepares(t *testing.T) {
prepare: prepareCustomTextsQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.custom_texts2.aggregate_id,`+
` projections.custom_texts2.sequence,`+
` projections.custom_texts2.creation_date,`+
` projections.custom_texts2.change_date,`+
` projections.custom_texts2.language,`+
` projections.custom_texts2.template,`+
` projections.custom_texts2.key,`+
` projections.custom_texts2.text,`+
` COUNT(*) OVER ()`+
` FROM projections.custom_texts2`),
[]string{
"aggregate_id",
"sequence",
"creation_date",
"change_date",
"language",
"template",
"key",
"text",
"count",
},
regexp.QuoteMeta(prepareCustomTextsStmt),
prepareCustomTextsCols,
[][]driver.Value{
{
"agg-id",
@@ -114,27 +111,8 @@ func Test_CustomTextPrepares(t *testing.T) {
prepare: prepareCustomTextsQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.custom_texts2.aggregate_id,`+
` projections.custom_texts2.sequence,`+
` projections.custom_texts2.creation_date,`+
` projections.custom_texts2.change_date,`+
` projections.custom_texts2.language,`+
` projections.custom_texts2.template,`+
` projections.custom_texts2.key,`+
` projections.custom_texts2.text,`+
` COUNT(*) OVER ()`+
` FROM projections.custom_texts2`),
[]string{
"aggregate_id",
"sequence",
"creation_date",
"change_date",
"language",
"template",
"key",
"text",
"count",
},
regexp.QuoteMeta(prepareCustomTextsStmt),
prepareCustomTextsCols,
[][]driver.Value{
{
"agg-id",
@@ -192,16 +170,7 @@ func Test_CustomTextPrepares(t *testing.T) {
prepare: prepareCustomTextsQuery,
want: want{
sqlExpectations: mockQueryErr(
regexp.QuoteMeta(`SELECT projections.custom_texts2.aggregate_id,`+
` projections.custom_texts2.sequence,`+
` projections.custom_texts2.creation_date,`+
` projections.custom_texts2.change_date,`+
` projections.custom_texts2.language,`+
` projections.custom_texts2.template,`+
` projections.custom_texts2.key,`+
` projections.custom_texts2.text,`+
` COUNT(*) OVER ()`+
` FROM projections.custom_texts2`),
regexp.QuoteMeta(prepareCustomTextsStmt),
sql.ErrConnDone,
),
err: func(err error) (error, bool) {
@@ -216,7 +185,7 @@ func Test_CustomTextPrepares(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...)
})
}
}