mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-16 12:58:00 +00:00
77cd430b3a
# Which Problems Are Solved Scheduled handlers use `eventstore.InstanceIDs` to get the all active instances within a given timeframe. This function scrapes through all events written within that time frame which can cause heavy load on the database. # How the Problems Are Solved A new query cache `activeInstances` is introduced which caches the ids of all instances queried by id or host within the configured timeframe. # Additional Changes - Changed `default.yaml` - Removed `HandleActiveInstances` from custom handler configs - Added `MaxActiveInstances` to define the maximal amount of cached instance ids - fixed start-from-init and start-from-setup to start auth and admin projections twice - fixed org cache invalidation to use correct index # Additional Context - part of #8999
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package projection
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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, 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
|
|
}
|