mirror of
https://github.com/zitadel/zitadel.git
synced 2025-02-28 22:57:23 +00:00
fix(eventstore): set created filters to exclusion sub-query (#9019)
# Which Problems Are Solved In eventstore queries with aggregate ID exclusion filters, filters on events creation date where not passed to the sub-query. This results in a high amount of returned rows from the sub-query and high overall query cost. # How the Problems Are Solved When CreatedAfter and CreatedBefore are used on the global search query, copy those filters to the sub-query. We already did this for the position column filter. # Additional Changes - none # Additional Context - Introduced in https://github.com/zitadel/zitadel/pull/8940 Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
parent
7a3ae8f499
commit
a81d42a61a
@ -285,7 +285,7 @@ func prepareConditions(criteria querier, query *repository.SearchQuery, useV1 bo
|
||||
|
||||
excludeAggregateIDs := query.ExcludeAggregateIDs
|
||||
if len(excludeAggregateIDs) > 0 {
|
||||
excludeAggregateIDs = append(excludeAggregateIDs, query.InstanceID, query.InstanceIDs, query.Position)
|
||||
excludeAggregateIDs = append(excludeAggregateIDs, query.InstanceID, query.InstanceIDs, query.Position, query.CreatedAfter, query.CreatedBefore)
|
||||
}
|
||||
excludeAggregateIDsClauses, excludeAggregateIDsArgs := prepareQuery(criteria, useV1, excludeAggregateIDs...)
|
||||
if excludeAggregateIDsClauses != "" {
|
||||
|
@ -1060,6 +1060,37 @@ func Test_query_events_mocked(t *testing.T) {
|
||||
wantErr: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "aggregate / event type, created after and exclusion, v2",
|
||||
args: args{
|
||||
dest: &[]*repository.Event{},
|
||||
query: eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
InstanceID("instanceID").
|
||||
OrderDesc().
|
||||
Limit(5).
|
||||
CreationDateAfter(time.Unix(123, 456)).
|
||||
AddQuery().
|
||||
AggregateTypes("notify").
|
||||
EventTypes("notify.foo.bar").
|
||||
Builder().
|
||||
ExcludeAggregateIDs().
|
||||
AggregateTypes("notify").
|
||||
EventTypes("notification.failed", "notification.success").
|
||||
Builder(),
|
||||
useV1: false,
|
||||
},
|
||||
fields: fields{
|
||||
mock: newMockClient(t).expectQuery(t,
|
||||
regexp.QuoteMeta(
|
||||
`SELECT created_at, event_type, "sequence", "position", payload, creator, "owner", instance_id, aggregate_type, aggregate_id, revision FROM eventstore.events2 WHERE instance_id = $1 AND aggregate_type = $2 AND event_type = $3 AND created_at > $4 AND aggregate_id NOT IN (SELECT aggregate_id FROM eventstore.events2 WHERE aggregate_type = $5 AND event_type = ANY($6) AND instance_id = $7 AND created_at > $8) ORDER BY "position" DESC, in_tx_order DESC LIMIT $9`,
|
||||
),
|
||||
[]driver.Value{"instanceID", eventstore.AggregateType("notify"), eventstore.EventType("notify.foo.bar"), time.Unix(123, 456), eventstore.AggregateType("notify"), []eventstore.EventType{"notification.failed", "notification.success"}, "instanceID", time.Unix(123, 456), uint64(5)},
|
||||
),
|
||||
},
|
||||
res: res{
|
||||
wantErr: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
crdb := NewCRDB(&database.DB{Database: new(testDB)})
|
||||
for _, tt := range tests {
|
||||
|
Loading…
x
Reference in New Issue
Block a user