mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
fix(query): query event editors only once per call (#7776)
Co-authored-by: Livio Spring <livio.a@gmail.com>
(cherry picked from commit f412687427
)
This commit is contained in:
parent
86e6c2a5df
commit
288525f180
@ -31,10 +31,11 @@ type eventsReducer struct {
|
||||
ctx context.Context
|
||||
q *Queries
|
||||
events []*Event
|
||||
editors map[string]*EventEditor
|
||||
}
|
||||
|
||||
func (r *eventsReducer) AppendEvents(events ...eventstore.Event) {
|
||||
r.events = append(r.events, r.q.convertEvents(r.ctx, events)...)
|
||||
r.events = append(r.events, r.convertEvents(r.ctx, events)...)
|
||||
}
|
||||
|
||||
func (r *eventsReducer) Reduce() error { return nil }
|
||||
@ -49,7 +50,7 @@ func (q *Queries) SearchEvents(ctx context.Context, query *eventstore.SearchQuer
|
||||
if auditLogRetention != 0 {
|
||||
query = filterAuditLogRetention(ctx, auditLogRetention, query)
|
||||
}
|
||||
reducer := &eventsReducer{ctx: ctx, q: q}
|
||||
reducer := &eventsReducer{ctx: ctx, q: q, editors: make(map[string]*EventEditor, query.GetLimit())}
|
||||
if err = q.eventstore.FilterToReducer(ctx, query, reducer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -78,24 +79,23 @@ func (q *Queries) SearchAggregateTypes(ctx context.Context) []string {
|
||||
return q.eventstore.AggregateTypes()
|
||||
}
|
||||
|
||||
func (q *Queries) convertEvents(ctx context.Context, events []eventstore.Event) []*Event {
|
||||
func (er *eventsReducer) convertEvents(ctx context.Context, events []eventstore.Event) []*Event {
|
||||
result := make([]*Event, len(events))
|
||||
users := make(map[string]*EventEditor)
|
||||
for i, event := range events {
|
||||
result[i] = q.convertEvent(ctx, event, users)
|
||||
result[i] = er.convertEvent(ctx, event)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (q *Queries) convertEvent(ctx context.Context, event eventstore.Event, users map[string]*EventEditor) *Event {
|
||||
func (er *eventsReducer) convertEvent(ctx context.Context, event eventstore.Event) *Event {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
var err error
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
editor, ok := users[event.Creator()]
|
||||
editor, ok := er.editors[event.Creator()]
|
||||
if !ok {
|
||||
editor = q.editorUserByID(ctx, event.Creator())
|
||||
users[event.Creator()] = editor
|
||||
editor = er.q.editorUserByID(ctx, event.Creator())
|
||||
er.editors[event.Creator()] = editor
|
||||
}
|
||||
|
||||
return &Event{
|
||||
|
Loading…
Reference in New Issue
Block a user