Merge two iterables of source IDs while preserving order and removing duplicates.
(
existing_ids: Iterable[str] | None, new_ids: Iterable[str] | None
)
| 4460 | |
| 4461 | |
| 4462 | def merge_source_ids( |
| 4463 | existing_ids: Iterable[str] | None, new_ids: Iterable[str] | None |
| 4464 | ) -> list[str]: |
| 4465 | """Merge two iterables of source IDs while preserving order and removing duplicates.""" |
| 4466 | |
| 4467 | merged: list[str] = [] |
| 4468 | seen: set[str] = set() |
| 4469 | |
| 4470 | for sequence in (existing_ids, new_ids): |
| 4471 | if not sequence: |
| 4472 | continue |
| 4473 | for source_id in sequence: |
| 4474 | if not source_id: |
| 4475 | continue |
| 4476 | if source_id not in seen: |
| 4477 | seen.add(source_id) |
| 4478 | merged.append(source_id) |
| 4479 | |
| 4480 | return merged |
| 4481 | |
| 4482 | |
| 4483 | def apply_source_ids_limit( |
no test coverage detected