Restore SelectCertificateStatuses to SA. (#4902)

And use it in ocsp-updater. This was cleaned up in #4546 because it was
unused, but it should have been in use in ocsp-updater now that we can
make a straightforward query here instead of a JOIN.

This makes the SA the single source of truth for what columns are in the
certificateStatus table.
This commit is contained in:
Jacob Hoffman-Andrews 2020-07-01 12:20:29 -07:00 committed by GitHub
parent ca26126ca9
commit fe79f727a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 18 deletions

View File

@ -142,21 +142,12 @@ func newUpdater(
}
func (updater *OCSPUpdater) findStaleOCSPResponses(oldestLastUpdatedTime time.Time, batchSize int) ([]core.CertificateStatus, error) {
var statuses []core.CertificateStatus
certStatusFields := "cs.serial, cs.status, cs.revokedDate, cs.notAfter, cs.revokedReason"
if features.Enabled(features.StoreIssuerInfo) {
certStatusFields += ", cs.issuerID"
}
_, err := updater.dbMap.Select(
&statuses,
fmt.Sprintf(`SELECT
%s
FROM certificateStatus AS cs
WHERE cs.ocspLastUpdated < :lastUpdate
AND NOT cs.isExpired
ORDER BY cs.ocspLastUpdated ASC
LIMIT :limit`, certStatusFields),
statuses, err := sa.SelectCertificateStatuses(
updater.dbMap,
`WHERE ocspLastUpdated < :lastUpdate
AND NOT isExpired
ORDER BY ocspLastUpdated ASC
LIMIT :limit`,
map[string]interface{}{
"lastUpdate": oldestLastUpdatedTime,
"limit": batchSize,

View File

@ -113,19 +113,34 @@ func certStatusFields() []string {
return []string{"serial", "status", "ocspLastUpdated", "revokedDate", "revokedReason", "lastExpirationNagSent", "ocspResponse", "notAfter", "isExpired", "issuerID"}
}
func certStatusFieldsSelect(restOfQuery string) string {
fields := strings.Join(certStatusFields(), ",")
return fmt.Sprintf("SELECT %s FROM certificateStatus %s", fields, restOfQuery)
}
// SelectCertificateStatus selects all fields of one certificate status model
func SelectCertificateStatus(s db.OneSelector, q string, args ...interface{}) (certStatusModel, error) {
var model certStatusModel
fields := strings.Join(certStatusFields(), ",")
err := s.SelectOne(
&model,
`SELECT `+fields+
` FROM certificateStatus `+q,
certStatusFieldsSelect(q),
args...,
)
return model, err
}
// SelectCertificateStatuses selects all fields of multiple certificate status
// objects
func SelectCertificateStatuses(s db.Selector, q string, args ...interface{}) ([]core.CertificateStatus, error) {
var models []core.CertificateStatus
_, err := s.Select(
&models,
certStatusFieldsSelect(q),
args...,
)
return models, err
}
var mediumBlobSize = int(math.Pow(2, 24))
type issuedNameModel struct {