Commit 3108e4b
fix(catalog): merge Source Cooperative product records field-by-field so no enrichment is lost (#1738)
* fix(catalog): merge product records field-by-field so no enrichment is lost
mergeProducts preferred whichever duplicate record was richer, but then
replaced the whole record with a spread of both. When the two catalog
sources enrich different fields (the feed adds a description, the
/products/* call adds tags), the whole-object overwrite silently dropped
whichever field the later record left empty.
Merge tags and description per-field, keeping whichever record actually
carries each one, so a merged entry always preserves both enrichments
regardless of the order the sources are merged in.
* fix(catalog): keep featured flag and first-seen fields when merging product records
The field-by-field merge introduced in this PR regressed 'Featured' products:
fetchCatalog merges [featured, recent], and a feed record (featured: false)
landing second clobbered the API record's featured: true for any product in
both lists, dropping the Featured badge and ranking boost. It also let a
thinner feed record overwrite the first-seen title/url/updatedAt.
Per-field merge now: tags/description prefer whichever record has them,
featured is true if either source flags it, and everything else keeps the
first-seen (API) record. Adds regression tests.
* fix(catalog): prefer first-seen description and tags when both sides have values
Fill empty description/tags from the later record, but keep the first-seen
value when both are non-empty so feed text cannot replace the API record.
Tighten the URL regression test and cover the both-non-empty case.
* Address Claude review feedback
- Rewrite the stale `mergeProducts` doc comment: it still described the old
"prefer the richer record" whole-object overwrite, which no longer matches
the per-field merge (empty description/tags filled from a later record,
`featured` OR-ed, everything else first-seen wins).
- Document the fill-only precedence as a deliberate scope limit, noting why it
is safe for the sole caller (`fetchCatalog` merges `featured` before
`recent`, and the feed contributes no tags) and flagging it for anyone who
reuses the function with two sources that can each populate the same field.
* Address CodeRabbit review feedback
- Scope the `mergeProducts` doc comment's "later value is dropped" rule
explicitly to `description` and `tags`, and note that `featured` is exempt
(a later `true` always wins via the OR). The previous wording read as if the
rule applied to every field, contradicting the featured semantics described
one sentence earlier.
- Fix singular/plural agreement now that the sentence covers two fields.
---------
Co-authored-by: giswqs <giswqs@gmail.com>1 parent 65e22f6 commit 3108e4b
2 files changed
Lines changed: 83 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
464 | 464 | | |
465 | 465 | | |
466 | 466 | | |
467 | | - | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
468 | 478 | | |
469 | 479 | | |
470 | 480 | | |
471 | 481 | | |
472 | 482 | | |
473 | 483 | | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
482 | 487 | | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
483 | 500 | | |
484 | 501 | | |
485 | 502 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
502 | 518 | | |
503 | 519 | | |
504 | 520 | | |
505 | 521 | | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
506 | 563 | | |
507 | 564 | | |
508 | 565 | | |
| |||
0 commit comments