diff --git a/satellite/accounting/projectlimitcache.go b/satellite/accounting/projectlimitcache.go index c20cb2c25..5d8506db4 100644 --- a/satellite/accounting/projectlimitcache.go +++ b/satellite/accounting/projectlimitcache.go @@ -91,6 +91,19 @@ func (c *ProjectLimitCache) GetBandwidthLimit(ctx context.Context, projectID uui return memory.Size(*projectLimits.Bandwidth), nil } +// GetSegmentLimit return the segment limit for a project ID. +func (c *ProjectLimitCache) GetSegmentLimit(ctx context.Context, projectID uuid.UUID) (_ memory.Size, err error) { + defer mon.Task()(&ctx)(&err) + projectLimits, err := c.GetLimits(ctx, projectID) + if err != nil { + return 0, err + } + if projectLimits.Segments == nil { + return memory.Size(c.defaultMaxSegments), nil + } + return memory.Size(*projectLimits.Segments), nil +} + // getProjectLimits returns project limits from DB. func (c *ProjectLimitCache) getProjectLimits(ctx context.Context, projectID uuid.UUID) (_ ProjectLimits, err error) { defer mon.Task()(&ctx, projectID)(&err) diff --git a/satellite/accounting/projectusage.go b/satellite/accounting/projectusage.go index 35b324a42..8a986bd74 100644 --- a/satellite/accounting/projectusage.go +++ b/satellite/accounting/projectusage.go @@ -258,12 +258,7 @@ func (usage *Service) GetProjectBandwidthLimit(ctx context.Context, projectID uu // GetProjectSegmentLimit returns current project segment limit. func (usage *Service) GetProjectSegmentLimit(ctx context.Context, projectID uuid.UUID) (_ memory.Size, err error) { defer mon.Task()(&ctx, projectID)(&err) - limits, err := usage.projectLimitCache.GetLimits(ctx, projectID) - if err != nil { - return 0, ErrProjectUsage.Wrap(err) - } - - return memory.Size(*limits.Usage), nil + return usage.projectLimitCache.GetSegmentLimit(ctx, projectID) } // UpdateProjectLimits sets new value for project's bandwidth and storage limit.