3e7fcce0b1
build / build (push) Successful in 1m11s
新增迁移50与每5分钟/手动持久同步,API只读本地;同步失败保留、权限阻断、租约与质量失效原子激活。 保留全量稳定分页/固定列,已存质量批量读取,元数据不反复解压长答案;详情安全Markdown与原文。 已运行整仓 make verify、源与副本隔离PG -race、真实只读源及隔离浏览器。 实际同步2525条;固定窗口640条本地中位1.46秒,对照直接源33.10秒。 停worker、缺源凭据、重启API后仍可查询;未更新8088,未修改生产原问答。
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package dobotaiops
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type QualityScope struct {
|
|
Keys []QualityKey
|
|
AsOf time.Time
|
|
}
|
|
|
|
func (c *RecordsRepository) ReadQualityScope(ctx context.Context, query RecordQuery) (QualityScope, error) {
|
|
if err := c.validateQueryWindow(query.Window); err != nil {
|
|
return QualityScope{}, err
|
|
}
|
|
if query.Cursor != "" {
|
|
return QualityScope{}, ErrInvalidQuery
|
|
}
|
|
pattern, err := recordKeywordPattern(query.Keyword)
|
|
if err != nil {
|
|
return QualityScope{}, err
|
|
}
|
|
result := QualityScope{Keys: []QualityKey{}}
|
|
err = c.transact(ctx, func(ctx context.Context, q querier) error {
|
|
if c.readAsOf(ctx, q, &result.AsOf) != nil {
|
|
return ErrUnavailable
|
|
}
|
|
scopeSQL := c.baseSQL + ` SELECT id,quality_hash,strpos(payload->>'answer',$5)>0,(payload->'source_coverage')::text FROM records WHERE `
|
|
if c.qualityScopeSQL != "" {
|
|
scopeSQL = c.qualityScopeSQL
|
|
}
|
|
rows, err := q.Query(ctx, scopeSQL+recordFilterSQL+` ORDER BY id LIMIT 5001`, query.Window.TenantKey, query.Window.Start, query.Window.End, pattern, noPublishedMarker)
|
|
if err != nil {
|
|
return ErrUnavailable
|
|
}
|
|
defer rows.Close()
|
|
for rows.Next() {
|
|
var key QualityKey
|
|
var raw string
|
|
if rows.Scan(&key.ID, &key.InputHash, &key.Marker, &raw) != nil || json.Unmarshal([]byte(raw), &key.Source) != nil {
|
|
return ErrUnavailable
|
|
}
|
|
if len(result.Keys) >= 5000 {
|
|
return ErrInvalidQuery
|
|
}
|
|
key.ObservedAt = result.AsOf
|
|
result.Keys = append(result.Keys, key)
|
|
}
|
|
return rows.Err()
|
|
})
|
|
return result, err
|
|
}
|