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:
parent
ca26126ca9
commit
fe79f727a9
|
@ -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,
|
||||
|
|
21
sa/model.go
21
sa/model.go
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue