fix
This commit is contained in:
@@ -358,14 +358,28 @@ func runCategorizeStep(ctx context.Context, e *Engine, companyID string, out *St
|
||||
return nil
|
||||
}
|
||||
|
||||
// MappedCategorySourceKey marks a mapped_data.category this pipeline wrote itself.
|
||||
//
|
||||
// Without it the write is indistinguishable from a feed-supplied category on the
|
||||
// next run, so Review showed an AI-chosen category as the product's "Original" and
|
||||
// every product looked already-categorised. $4 carries the step that chose it
|
||||
// (mapped / vector / llm); only "mapped" means the feed actually supplied one.
|
||||
const MappedCategorySourceKey = "category_source"
|
||||
|
||||
// persistMappedCategorySQL writes a taxonomy unique_id onto mapped_data.category
|
||||
// when the mapped value is still empty (so Products UI + reprocess stick).
|
||||
// when the mapped value is still empty (so Products UI + reprocess stick), and
|
||||
// records who chose it alongside.
|
||||
const persistMappedCategorySQL = `
|
||||
UPDATE raw_products
|
||||
SET mapped_data = jsonb_set(
|
||||
COALESCE(mapped_data, '{}'::jsonb),
|
||||
'{category}',
|
||||
to_jsonb($3::text),
|
||||
jsonb_set(
|
||||
COALESCE(mapped_data, '{}'::jsonb),
|
||||
'{category}',
|
||||
to_jsonb($3::text),
|
||||
true
|
||||
),
|
||||
'{category_source}',
|
||||
to_jsonb($4::text),
|
||||
true
|
||||
),
|
||||
updated_at = now()
|
||||
|
||||
@@ -1701,7 +1701,13 @@ func (p *Pipeline) processOne(ctx context.Context, companyID, jobID uuid.UUID, i
|
||||
// Stick taxonomy unique_id onto mapped_data.category when still empty so the
|
||||
// Products UI (reads mapped) and reprocess keep the AI/vector/mapped pick.
|
||||
if cat := strings.TrimSpace(result.Category); cat != "" {
|
||||
if _, err := tx.Exec(ctx, persistMappedCategorySQL, it.RawID, companyID, cat); err != nil {
|
||||
// Record who chose it: a category this pipeline derived must not read back
|
||||
// as the feed's own on the next run (see MappedCategorySourceKey).
|
||||
catSource, _ := result.FieldSources["category"].(string)
|
||||
if strings.TrimSpace(catSource) == "" {
|
||||
catSource = "pipeline"
|
||||
}
|
||||
if _, err := tx.Exec(ctx, persistMappedCategorySQL, it.RawID, companyID, cat, catSource); err != nil {
|
||||
return false, 0, result, fmt.Errorf("persist mapped category: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user