mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:17:32 +00:00
fix(eventstore): prevent allocation of filtered events (#6749)
* fix(eventstore): prevent allocation of filtered events Directly reduce each event obtained from a sql.Rows scan, so that we do not have to allocate all events in a slice. * reinstate the mutex as RWMutex * scan data directly * add todos * fix(writemodels): add reduce of parent * test: remove comment * update comments --------- Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -402,6 +401,7 @@ func (repo *testQuerier) Health(ctx context.Context) error {
|
||||
func (repo *testQuerier) CreateInstance(ctx context.Context, instance string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *testQuerier) Filter(ctx context.Context, searchQuery *SearchQueryBuilder) ([]Event, error) {
|
||||
if repo.err != nil {
|
||||
return nil, repo.err
|
||||
@@ -409,6 +409,18 @@ func (repo *testQuerier) Filter(ctx context.Context, searchQuery *SearchQueryBui
|
||||
return repo.events, nil
|
||||
}
|
||||
|
||||
func (repo *testQuerier) FilterToReducer(ctx context.Context, searchQuery *SearchQueryBuilder, reduce Reducer) error {
|
||||
if repo.err != nil {
|
||||
return repo.err
|
||||
}
|
||||
for _, event := range repo.events {
|
||||
if err := reduce(event); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *testQuerier) LatestSequence(ctx context.Context, queryFactory *SearchQueryBuilder) (float64, error) {
|
||||
if repo.err != nil {
|
||||
return 0, repo.err
|
||||
@@ -684,7 +696,6 @@ func TestEventstore_Push(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
es := &Eventstore{
|
||||
pusher: tt.fields.pusher,
|
||||
interceptorMutex: sync.Mutex{},
|
||||
eventInterceptors: map[EventType]eventTypeInterceptors{},
|
||||
}
|
||||
for eventType, mapper := range tt.fields.eventMapper {
|
||||
@@ -816,7 +827,6 @@ func TestEventstore_FilterEvents(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
es := &Eventstore{
|
||||
querier: tt.fields.repo,
|
||||
interceptorMutex: sync.Mutex{},
|
||||
eventInterceptors: map[EventType]eventTypeInterceptors{},
|
||||
}
|
||||
|
||||
@@ -1121,7 +1131,6 @@ func TestEventstore_FilterToReducer(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
es := &Eventstore{
|
||||
querier: tt.fields.repo,
|
||||
interceptorMutex: sync.Mutex{},
|
||||
eventInterceptors: map[EventType]eventTypeInterceptors{},
|
||||
}
|
||||
for eventType, mapper := range tt.fields.eventMapper {
|
||||
@@ -1238,7 +1247,6 @@ func TestEventstore_mapEvents(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
es := &Eventstore{
|
||||
interceptorMutex: sync.Mutex{},
|
||||
eventInterceptors: map[EventType]eventTypeInterceptors{},
|
||||
}
|
||||
for eventType, mapper := range tt.fields.eventMapper {
|
||||
|
Reference in New Issue
Block a user