3e7fcce0b1
build / build (push) Successful in 1m11s
新增迁移50与每5分钟/手动持久同步,API只读本地;同步失败保留、权限阻断、租约与质量失效原子激活。 保留全量稳定分页/固定列,已存质量批量读取,元数据不反复解压长答案;详情安全Markdown与原文。 已运行整仓 make verify、源与副本隔离PG -race、真实只读源及隔离浏览器。 实际同步2525条;固定窗口640条本地中位1.46秒,对照直接源33.10秒。 停worker、缺源凭据、重启API后仍可查询;未更新8088,未修改生产原问答。
63 lines
2.2 KiB
Go
63 lines
2.2 KiB
Go
package qaopsquality
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"knowledge-governance/internal/dobotaiops"
|
|
)
|
|
|
|
// ReadViews projects quality already observed by mirror activation. It performs
|
|
// one SELECT, never inserts inputs/checks or advances an observation epoch.
|
|
func (s *Store) ReadViews(ctx context.Context, keys []dobotaiops.QualityKey) (map[string]View, error) {
|
|
if !s.available() {
|
|
return nil, ErrUnavailable
|
|
}
|
|
if len(keys) > 5000 {
|
|
return nil, ErrInvalid
|
|
}
|
|
expected := map[string]string{}
|
|
ids := make([]string, 0, len(keys))
|
|
for _, k := range keys {
|
|
if !validID(k.ID) || !hashPattern.MatchString(k.InputHash) {
|
|
return nil, ErrInvalid
|
|
}
|
|
if old, exists := expected[k.ID]; exists {
|
|
if old != k.InputHash {
|
|
return nil, ErrInvalid
|
|
}
|
|
continue
|
|
}
|
|
expected[k.ID] = k.InputHash
|
|
ids = append(ids, k.ID)
|
|
}
|
|
out := map[string]View{}
|
|
if len(ids) == 0 {
|
|
return out, nil
|
|
}
|
|
rows, e := s.pool.Query(ctx, `SELECT h.record_id,h.input_hash,h.input_epoch,h.review_revision,`+checkObject+`::text,COALESCE((SELECT `+reviewObject+` FROM qa_ops_quality_reviews r WHERE r.tenant_key=h.tenant_key AND r.record_id=h.record_id AND r.revision=h.review_revision),'null'::jsonb)::text FROM qa_ops_quality_records h JOIN qa_ops_quality_inputs i ON i.tenant_key=h.tenant_key AND i.record_id=h.record_id AND i.input_epoch=h.input_epoch JOIN qa_ops_quality_checks c ON c.tenant_key=h.tenant_key AND c.record_id=h.record_id AND c.input_epoch=h.input_epoch AND c.rule_version=$3 WHERE h.tenant_key=$1 AND h.record_id=ANY($2::text[])`, s.tenant, ids, dobotaiops.CoverageRuleVersion)
|
|
if e != nil {
|
|
return nil, ErrUnavailable
|
|
}
|
|
defer rows.Close()
|
|
for rows.Next() {
|
|
var id, hash, checkRaw, reviewRaw string
|
|
var epoch, revision int64
|
|
if rows.Scan(&id, &hash, &epoch, &revision, &checkRaw, &reviewRaw) != nil {
|
|
return nil, ErrUnavailable
|
|
}
|
|
if expected[id] != hash {
|
|
return nil, ErrConflict
|
|
}
|
|
var automatic Check
|
|
var review *Review
|
|
if json.Unmarshal([]byte(checkRaw), &automatic) != nil || json.Unmarshal([]byte(reviewRaw), &review) != nil {
|
|
return nil, ErrUnavailable
|
|
}
|
|
out[id] = Project(hash, epoch, revision, automatic, review)
|
|
}
|
|
if rows.Err() != nil || len(out) != len(ids) {
|
|
return nil, ErrUnavailable
|
|
}
|
|
return out, nil
|
|
}
|