mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
1d84635836
# Which Problems Are Solved To improve performance a new table and method is implemented on eventstore. The goal of this table is to index searchable fields on command side to use it on command and query side. The table allows to store one primitive value (numeric, text) per row. The eventstore framework is extended by the `Search`-method which allows to search for objects. The `Command`-interface is extended by the `SearchOperations()`-method which does manipulate the the `search`-table. # How the Problems Are Solved This PR adds the capability of improving performance for command and query side by using the `Search`-method of the eventstore instead of using one of the `Filter`-methods. # Open Tasks - [x] Add feature flag - [x] Unit tests - [ ] ~~Benchmarks if needed~~ - [x] Ensure no behavior change - [x] Add setup step to fill table with current data - [x] Add projection which ensures data added between setup and start of the new version are also added to the table # Additional Changes The `Search`-method is currently used by `ProjectGrant`-command side. # Additional Context - Closes https://github.com/zitadel/zitadel/issues/8094
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package projection
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
|
)
|
|
|
|
var _ handler.EventStore = (*mockEventStore)(nil)
|
|
|
|
type mockEventStore struct {
|
|
instanceIDsResponse [][]string
|
|
instanceIDCounter int
|
|
filterResponse [][]eventstore.Event
|
|
filterCounter int
|
|
pushResponse [][]eventstore.Event
|
|
pushCounter int
|
|
}
|
|
|
|
func newMockEventStore() *mockEventStore {
|
|
return new(mockEventStore)
|
|
}
|
|
|
|
func (m *mockEventStore) appendFilterResponse(events []eventstore.Event) *mockEventStore {
|
|
m.filterResponse = append(m.filterResponse, events)
|
|
return m
|
|
}
|
|
|
|
func (m *mockEventStore) InstanceIDs(ctx context.Context, _ time.Duration, _ bool, query *eventstore.SearchQueryBuilder) ([]string, error) {
|
|
m.instanceIDCounter++
|
|
return m.instanceIDsResponse[m.instanceIDCounter-1], nil
|
|
}
|
|
|
|
func (m *mockEventStore) Filter(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
|
m.filterCounter++
|
|
return m.filterResponse[m.filterCounter-1], nil
|
|
}
|
|
|
|
func (m *mockEventStore) FilterToQueryReducer(ctx context.Context, reducer eventstore.QueryReducer) error {
|
|
m.filterCounter++
|
|
events := m.filterResponse[m.filterCounter-1]
|
|
reducer.AppendEvents(events...)
|
|
return reducer.Reduce()
|
|
}
|
|
|
|
func (m *mockEventStore) Push(ctx context.Context, cmds ...eventstore.Command) ([]eventstore.Event, error) {
|
|
m.pushCounter++
|
|
return m.pushResponse[m.pushCounter-1], nil
|
|
}
|
|
|
|
func (m *mockEventStore) FillFields(ctx context.Context, events ...eventstore.FillFieldsEvent) error {
|
|
return nil
|
|
}
|