Skip to content

Commit

Permalink
improve quota handling in the graph API
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Mar 28, 2022
1 parent a9e0ecf commit 67a1994
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions graph/pkg/service/v0/drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,16 +584,33 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage
return nil, err
}

var remaining int64
if res.Opaque != nil {
m := res.Opaque.Map
if e, ok := m["remaining"]; ok {
remaining, _ = strconv.ParseInt(string(e.Value), 10, 64)
}
}

total := int64(res.TotalBytes)

used := int64(res.UsedBytes)
remaining := total - used
qta := libregraph.Quota{
Remaining: &remaining,
Total: &total,
Used: &used,
}
state := calculateQuotaState(total, used)

var t int64
if total != 0 {
// A quota was set
qta.Total = &total
t = total
} else {
// Quota was not set
// Use remaining bytes to calculate state
t = remaining
}
state := calculateQuotaState(t, used)
qta.State = &state

return &qta, nil
Expand Down

0 comments on commit 67a1994

Please sign in to comment.