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,46 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/repository/quota"
|
||||
)
|
||||
|
||||
type quotaNotificationsReadModel struct {
|
||||
eventstore.ReadModel
|
||||
periodStart time.Time
|
||||
latestNotifiedThresholds map[string]uint16
|
||||
}
|
||||
|
||||
func newQuotaNotificationsReadModel(aggregateId, instanceId, resourceOwner string, periodStart time.Time) *quotaNotificationsReadModel {
|
||||
return "aNotificationsReadModel{
|
||||
ReadModel: eventstore.ReadModel{
|
||||
AggregateID: aggregateId,
|
||||
InstanceID: instanceId,
|
||||
ResourceOwner: resourceOwner,
|
||||
},
|
||||
periodStart: periodStart,
|
||||
latestNotifiedThresholds: make(map[string]uint16),
|
||||
}
|
||||
}
|
||||
|
||||
func (rm *quotaNotificationsReadModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(rm.ResourceOwner).
|
||||
AllowTimeTravel().
|
||||
AddQuery().
|
||||
InstanceID(rm.InstanceID).
|
||||
AggregateTypes(quota.AggregateType).
|
||||
AggregateIDs(rm.AggregateID).
|
||||
CreationDateAfter(rm.periodStart).
|
||||
EventTypes(quota.NotifiedEventType).Builder()
|
||||
}
|
||||
|
||||
func (rm *quotaNotificationsReadModel) Reduce() error {
|
||||
for _, event := range rm.Events {
|
||||
e := event.(*quota.NotifiedEvent)
|
||||
rm.latestNotifiedThresholds[e.ID] = e.Threshold
|
||||
}
|
||||
return rm.ReadModel.Reduce()
|
||||
}
|
||||
Reference in New Issue
Block a user