Only count pending authorizations in CountPendingAuthorizations (#2324)
`CountPendingAuthorizations` wasn't updated when we added authorization deactivation which means deactivated authorizations count towards the pending authorization limit. This PR adds a `AND status = 'pending'` clause to the existing SQL query. Currently there is no index on the `status` column but as we are already filtering using the `registrationID, expires` index this doesn't have a significant impact on the query performance. Fixes #2309.
This commit is contained in:
parent
af61757f34
commit
b14cd0657b
4
sa/sa.go
4
sa/sa.go
|
|
@ -886,10 +886,12 @@ func (ssa *SQLStorageAuthority) CountPendingAuthorizations(ctx context.Context,
|
||||||
err = ssa.dbMap.SelectOne(&count,
|
err = ssa.dbMap.SelectOne(&count,
|
||||||
`SELECT count(1) FROM pendingAuthorizations
|
`SELECT count(1) FROM pendingAuthorizations
|
||||||
WHERE registrationID = :regID AND
|
WHERE registrationID = :regID AND
|
||||||
expires > :now`,
|
expires > :now AND
|
||||||
|
status = :pending`,
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"regID": regID,
|
"regID": regID,
|
||||||
"now": ssa.clk.Now(),
|
"now": ssa.clk.Now(),
|
||||||
|
"pending": string(core.StatusPending),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,13 @@ func TestCountPendingAuthorizations(t *testing.T) {
|
||||||
test.AssertNotError(t, err, "Couldn't create new pending authorization")
|
test.AssertNotError(t, err, "Couldn't create new pending authorization")
|
||||||
count, err := sa.CountPendingAuthorizations(ctx, reg.ID)
|
count, err := sa.CountPendingAuthorizations(ctx, reg.ID)
|
||||||
test.AssertNotError(t, err, "Couldn't count pending authorizations")
|
test.AssertNotError(t, err, "Couldn't count pending authorizations")
|
||||||
|
test.AssertEquals(t, count, 0)
|
||||||
|
|
||||||
|
pendingAuthz.Status = core.StatusPending
|
||||||
|
pendingAuthz, err = sa.NewPendingAuthorization(ctx, pendingAuthz)
|
||||||
|
test.AssertNotError(t, err, "Couldn't create new pending authorization")
|
||||||
|
count, err = sa.CountPendingAuthorizations(ctx, reg.ID)
|
||||||
|
test.AssertNotError(t, err, "Couldn't count pending authorizations")
|
||||||
test.AssertEquals(t, count, 1)
|
test.AssertEquals(t, count, 1)
|
||||||
|
|
||||||
fc.Add(2 * time.Hour)
|
fc.Add(2 * time.Hour)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue