fix(qa): 首批即显并统一五字段后端筛选
build / build (push) Successful in 1m19s

列表正文改为按需读取;保留完整导出、版本隔离和有效标签筛选。
验证:前端全量、Go全量及隔离PG全mirror竞态通过;覆盖首批回调、续载失败与筛选分页。
This commit is contained in:
姚章浩
2026-10-25 12:45:31 +08:00
parent 65653e5c01
commit 00c4c13283
26 changed files with 836 additions and 39 deletions
+35
View File
@@ -0,0 +1,35 @@
package dobotaiops
import (
"strings"
"unicode/utf8"
)
var QualityFilterKeys = []string{"coverage", "is_correct", "product_category", "problem_type", "root_cause"}
func ValidQualityFilters(filters map[string]string) bool {
if len(filters) > 5 {
return false
}
for key, value := range filters {
found := false
for _, allowed := range QualityFilterKeys {
if key == allowed {
found = true
}
}
if !found || value == "" || !utf8.ValidString(value) || utf8.RuneCountInString(value) > 200 || strings.ContainsRune(value, 0) {
return false
}
if value == "__empty__" {
continue
}
if key == "coverage" && value != "是" && value != "否" && value != "否但不计入" && value != "部分覆盖" && value != "待确认" {
return false
}
if key == "is_correct" && value != "是" && value != "否" && value != "待确认" {
return false
}
}
return true
}
+5
View File
@@ -38,6 +38,11 @@ func NewRecordsRepository(o RecordsRepositoryOptions) *RecordsRepository {
}
return &RecordsRepository{summarySQL: o.SummarySQL, qualityScopeSQL: o.QualityScopeSQL, baseSQL: o.BaseSQL, transact: o.Transaction, validateQueryWindow: o.ValidateWindow, readAsOf: asOf, tenant: o.TenantKey}
}
func (c *RecordsRepository) WithSummarySQL(sql string) *RecordsRepository {
out := *c
out.summarySQL = sql
return &out
}
func (c *Client) recordRepository() *RecordsRepository {
return NewRecordsRepository(RecordsRepositoryOptions{BaseSQL: recordsBaseSQL, Transaction: c.withReadOnlyTx, ValidateWindow: c.validateQueryWindow})
}
+34 -7
View File
@@ -69,6 +69,7 @@ type RecordFeedback struct {
}
type Record struct {
ContentProjection string `json:"content_projection,omitempty"`
FieldEditRevision int64 `json:"field_edit_revision,omitempty"`
BackgroundTasks json.RawMessage `json:"background_tasks,omitempty"`
RecordOrigin string `json:"record_origin,omitempty"`
@@ -96,10 +97,14 @@ type Record struct {
}
type RecordQuery struct {
Window Window
Keyword string
Cursor string
Limit int
Summary bool
Filters map[string]string
MatchIDs []string
MatchVersion string
Window Window
Keyword string
Cursor string
Limit int
}
type QualityKey struct {
@@ -200,6 +205,16 @@ func (c *RecordsRepository) ListRecords(ctx context.Context, query RecordQuery)
return RecordPage{}, fmt.Errorf("%w: invalid record filters", ErrInvalidQuery)
}
scopeBytes, _ := json.Marshal([]string{query.Window.TenantKey, query.Window.Start.UTC().Format(time.RFC3339Nano), query.Window.End.UTC().Format(time.RFC3339Nano), query.Keyword})
if len(query.Filters) > 0 {
if query.MatchIDs == nil {
return RecordPage{}, ErrInvalidQuery
}
extra, _ := json.Marshal(struct {
Filters map[string]string
Version string
}{query.Filters, query.MatchVersion})
scopeBytes = append(scopeBytes, extra...)
}
scopeSum := sha256.Sum256(scopeBytes)
scope := hex.EncodeToString(scopeSum[:])
var cursor recordCursor
@@ -226,7 +241,13 @@ func (c *RecordsRepository) ListRecords(ctx context.Context, query RecordQuery)
if c.summarySQL != "" {
summarySQL = c.summarySQL
}
if err := q.QueryRow(ctx, summarySQL+recordFilterSQL, append(args, noPublishedMarker)...).Scan(&page.Total, &rawColumns, &rawActors, &rawQuality); err != nil {
summaryFilter := recordFilterSQL
summaryArgs := append(append([]any{}, args...), noPublishedMarker)
if query.MatchIDs != nil {
summaryFilter += " AND id=ANY($6::text[])"
summaryArgs = append(summaryArgs, query.MatchIDs)
}
if err := q.QueryRow(ctx, summarySQL+summaryFilter, summaryArgs...).Scan(&page.Total, &rawColumns, &rawActors, &rawQuality); err != nil {
return fmt.Errorf("%w: record count failed", ErrUnavailable)
}
if json.Unmarshal([]byte(rawQuality), &page.ScopeQuality) != nil {
@@ -247,8 +268,14 @@ func (c *RecordsRepository) ListRecords(ctx context.Context, query RecordQuery)
page.Columns = append(page.Columns, column)
}
}
rows, err := q.Query(ctx, c.baseSQL+` SELECT payload::text FROM records WHERE `+recordFilterSQL+`
AND ($5::timestamptz IS NULL OR (asked_at,id)<($5,$6)) ORDER BY asked_at DESC,id DESC LIMIT $7`, append(args, before, cursor.ID, query.Limit+1)...)
listFilter := recordFilterSQL
listArgs := append(append([]any{}, args...), before, cursor.ID, query.Limit+1)
if query.MatchIDs != nil {
listFilter += " AND id=ANY($8::text[])"
listArgs = append(listArgs, query.MatchIDs)
}
rows, err := q.Query(ctx, c.baseSQL+` SELECT payload::text FROM records WHERE `+listFilter+`
AND ($5::timestamptz IS NULL OR (asked_at,id)<($5,$6)) ORDER BY asked_at DESC,id DESC LIMIT $7`, listArgs...)
if err != nil {
return fmt.Errorf("%w: record list failed", ErrUnavailable)
}