From 9638e4d12a7fafeaf6a3eb8328ab0ed6db812a86 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Fri, 18 Mar 2022 18:28:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96OCSP=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=85=BC=E5=AE=B9MySQL=205.7.22=E4=BB=A5?= =?UTF-8?q?=E4=B8=8B=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/ssl_cert_dao.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/internal/db/models/ssl_cert_dao.go b/internal/db/models/ssl_cert_dao.go index 7a878755..d780c177 100644 --- a/internal/db/models/ssl_cert_dao.go +++ b/internal/db/models/ssl_cert_dao.go @@ -378,13 +378,28 @@ func (this *SSLCertDAO) ListCertsToUpdateOCSP(tx *dbs.Tx, maxAge int, size int64 if maxAge <= 0 { maxAge = 7200 } - _, err = this.Query(tx). + + var query = this.Query(tx). State(SSLCertStateEnabled). Where("ocspUpdatedAt<:timestamp"). - Param("timestamp", time.Now().Unix()-int64(maxAge)). + Param("timestamp", time.Now().Unix()-int64(maxAge)) - // TODO 需要排除没有被server使用的policy,或许可以增加一个字段记录policy最近使用时间 - Where("JSON_CONTAINS((SELECT JSON_ARRAYAGG(JSON_EXTRACT(certs, '$[*].certId')) FROM edgeSSLPolicies WHERE state=1 AND ocspIsOn=1 AND certs IS NOT NULL), CAST(id AS CHAR))"). + // TODO 需要排除没有被server使用的policy,或许可以增加一个字段记录policy最近使用时间 + + // 检查函数 + var JSONArrayAggIsEnabled = false + _, err = this.Object().Instance.Exec("SELECT JSON_ARRAYAGG('1')") + if err == nil { + JSONArrayAggIsEnabled = true + } + + if JSONArrayAggIsEnabled { + query.Where("JSON_CONTAINS((SELECT JSON_ARRAYAGG(JSON_EXTRACT(certs, '$[*].certId')) FROM edgeSSLPolicies WHERE state=1 AND ocspIsOn=1 AND certs IS NOT NULL), CAST(id AS CHAR))") + } else { + query.Where("JSON_CONTAINS((SELECT REPLACE(GROUP_CONCAT(JSON_EXTRACT(certs, '$[*].certId')), '],[', ',') FROM edgeSSLPolicies WHERE state=1 AND ocspIsOn=1 AND certs IS NOT NULL), CAST(id AS CHAR))") + } + + _, err = query. Asc("ocspUpdatedAt"). Limit(size). Slice(&result).