Skip to content

Commit fe79f72

Browse files
authored
Restore SelectCertificateStatuses to SA. (letsencrypt#4902)
And use it in ocsp-updater. This was cleaned up in letsencrypt#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.
1 parent ca26126 commit fe79f72

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

cmd/ocsp-updater/main.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,12 @@ func newUpdater(
142142
}
143143

144144
func (updater *OCSPUpdater) findStaleOCSPResponses(oldestLastUpdatedTime time.Time, batchSize int) ([]core.CertificateStatus, error) {
145-
var statuses []core.CertificateStatus
146-
147-
certStatusFields := "cs.serial, cs.status, cs.revokedDate, cs.notAfter, cs.revokedReason"
148-
if features.Enabled(features.StoreIssuerInfo) {
149-
certStatusFields += ", cs.issuerID"
150-
}
151-
_, err := updater.dbMap.Select(
152-
&statuses,
153-
fmt.Sprintf(`SELECT
154-
%s
155-
FROM certificateStatus AS cs
156-
WHERE cs.ocspLastUpdated < :lastUpdate
157-
AND NOT cs.isExpired
158-
ORDER BY cs.ocspLastUpdated ASC
159-
LIMIT :limit`, certStatusFields),
145+
statuses, err := sa.SelectCertificateStatuses(
146+
updater.dbMap,
147+
`WHERE ocspLastUpdated < :lastUpdate
148+
AND NOT isExpired
149+
ORDER BY ocspLastUpdated ASC
150+
LIMIT :limit`,
160151
map[string]interface{}{
161152
"lastUpdate": oldestLastUpdatedTime,
162153
"limit": batchSize,

sa/model.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,34 @@ func certStatusFields() []string {
113113
return []string{"serial", "status", "ocspLastUpdated", "revokedDate", "revokedReason", "lastExpirationNagSent", "ocspResponse", "notAfter", "isExpired", "issuerID"}
114114
}
115115

116+
func certStatusFieldsSelect(restOfQuery string) string {
117+
fields := strings.Join(certStatusFields(), ",")
118+
return fmt.Sprintf("SELECT %s FROM certificateStatus %s", fields, restOfQuery)
119+
}
120+
116121
// SelectCertificateStatus selects all fields of one certificate status model
117122
func SelectCertificateStatus(s db.OneSelector, q string, args ...interface{}) (certStatusModel, error) {
118123
var model certStatusModel
119-
fields := strings.Join(certStatusFields(), ",")
120124
err := s.SelectOne(
121125
&model,
122-
`SELECT `+fields+
123-
` FROM certificateStatus `+q,
126+
certStatusFieldsSelect(q),
124127
args...,
125128
)
126129
return model, err
127130
}
128131

132+
// SelectCertificateStatuses selects all fields of multiple certificate status
133+
// objects
134+
func SelectCertificateStatuses(s db.Selector, q string, args ...interface{}) ([]core.CertificateStatus, error) {
135+
var models []core.CertificateStatus
136+
_, err := s.Select(
137+
&models,
138+
certStatusFieldsSelect(q),
139+
args...,
140+
)
141+
return models, err
142+
}
143+
129144
var mediumBlobSize = int(math.Pow(2, 24))
130145

131146
type issuedNameModel struct {

0 commit comments

Comments
 (0)