From b14cd0657b98888c936e6dfb9b9a5825c9cb3762 Mon Sep 17 00:00:00 2001 From: Roland Bracewell Shoemaker Date: Thu, 10 Nov 2016 14:47:50 -0800 Subject: [PATCH] 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. --- sa/sa.go | 10 ++++++---- sa/sa_test.go | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sa/sa.go b/sa/sa.go index 597bd76d8..950446bf9 100644 --- a/sa/sa.go +++ b/sa/sa.go @@ -885,11 +885,13 @@ func (ssa *SQLStorageAuthority) CountCertificatesRange(ctx context.Context, star func (ssa *SQLStorageAuthority) CountPendingAuthorizations(ctx context.Context, regID int64) (count int, err error) { err = ssa.dbMap.SelectOne(&count, `SELECT count(1) FROM pendingAuthorizations - WHERE registrationID = :regID AND - expires > :now`, + WHERE registrationID = :regID AND + expires > :now AND + status = :pending`, map[string]interface{}{ - "regID": regID, - "now": ssa.clk.Now(), + "regID": regID, + "now": ssa.clk.Now(), + "pending": string(core.StatusPending), }) return } diff --git a/sa/sa_test.go b/sa/sa_test.go index 9572e9792..e7770612d 100644 --- a/sa/sa_test.go +++ b/sa/sa_test.go @@ -152,6 +152,13 @@ func TestCountPendingAuthorizations(t *testing.T) { 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, 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) fc.Add(2 * time.Hour)