mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-29 15:38:52 +00:00
perf: query data AS OF SYSTEM TIME (#5231)
Queries the data in the storage layser at the timestamp when the call hit the API layer
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/repository/quota"
|
||||
)
|
||||
|
||||
type quotaReadModel struct {
|
||||
eventstore.ReadModel
|
||||
unit quota.Unit
|
||||
active bool
|
||||
config *quota.AddedEvent
|
||||
}
|
||||
|
||||
// newQuotaReadModel aggregateId is filled by reducing unit matching events
|
||||
func newQuotaReadModel(instanceId, resourceOwner string, unit quota.Unit) *quotaReadModel {
|
||||
return "aReadModel{
|
||||
ReadModel: eventstore.ReadModel{
|
||||
InstanceID: instanceId,
|
||||
ResourceOwner: resourceOwner,
|
||||
},
|
||||
unit: unit,
|
||||
}
|
||||
}
|
||||
|
||||
func (rm *quotaReadModel) Query() *eventstore.SearchQueryBuilder {
|
||||
query := eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(rm.ResourceOwner).
|
||||
AllowTimeTravel().
|
||||
AddQuery().
|
||||
InstanceID(rm.InstanceID).
|
||||
AggregateTypes(quota.AggregateType).
|
||||
EventTypes(
|
||||
quota.AddedEventType,
|
||||
quota.RemovedEventType,
|
||||
).EventData(map[string]interface{}{"unit": rm.unit})
|
||||
|
||||
return query.Builder()
|
||||
}
|
||||
|
||||
func (rm *quotaReadModel) Reduce() error {
|
||||
for _, event := range rm.Events {
|
||||
switch e := event.(type) {
|
||||
case *quota.AddedEvent:
|
||||
rm.AggregateID = e.Aggregate().ID
|
||||
rm.active = true
|
||||
rm.config = e
|
||||
case *quota.RemovedEvent:
|
||||
rm.AggregateID = e.Aggregate().ID
|
||||
rm.active = false
|
||||
rm.config = nil
|
||||
}
|
||||
}
|
||||
return rm.ReadModel.Reduce()
|
||||
}
|
||||
Reference in New Issue
Block a user