mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
e38abdcdf3
Queries the data in the storage layser at the timestamp when the call hit the API layer
31 lines
922 B
Go
31 lines
922 B
Go
package query
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/quota"
|
|
)
|
|
|
|
func (q *Queries) GetCurrentQuotaPeriod(ctx context.Context, instanceID string, unit quota.Unit) (*quota.AddedEvent, time.Time, error) {
|
|
rm, err := q.getQuotaReadModel(ctx, instanceID, instanceID, unit)
|
|
if err != nil || !rm.active {
|
|
return nil, time.Time{}, err
|
|
}
|
|
|
|
return rm.config, pushPeriodStart(rm.config.From, rm.config.ResetInterval, time.Now()), nil
|
|
}
|
|
|
|
func pushPeriodStart(from time.Time, interval time.Duration, now time.Time) time.Time {
|
|
next := from.Add(interval)
|
|
if next.After(now) {
|
|
return from
|
|
}
|
|
return pushPeriodStart(next, interval, now)
|
|
}
|
|
|
|
func (q *Queries) getQuotaReadModel(ctx context.Context, instanceId, resourceOwner string, unit quota.Unit) (*quotaReadModel, error) {
|
|
rm := newQuotaReadModel(instanceId, resourceOwner, unit)
|
|
return rm, q.eventstore.FilterToQueryReducer(ctx, rm)
|
|
}
|