Skip to content

PPTX: index relationships by id on import and by target on export - #1739

Merged
dylanmtaylor merged 1 commit into
mainfrom
fix/sec-pptx-rels-index
Nov 4, 2026
Merged

dylanmtaylor merged 1 commit into
mainfrom
fix/sec-pptx-rels-index

Conversation

@dylanmtaylor

@dylanmtaylor dylanmtaylor commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What was wrong

Two relationship lookups in crates/pptx/src/opc.rs scanned a list that the file controls:

  • Reading: Rels::get(id) searched the part's whole relationship list for each id it resolved. A slide list resolves an id per slide, so many references against a long .rels part cost references × relationships.
  • Writing: RelsOut::add checked for an identical relationship by scanning every relationship already added to the part. Export adds one per hyperlink, picture and so on, so many distinct hyperlink targets made export quadratic.

What changed

  • Rels keeps an id → index map, filled while the .rels part is parsed. get (and so target) is a map lookup. A repeated id still resolves to its first relationship, as before.
  • RelsOut keeps a (type, target, external) → id map. add reuses an id through it. add_new also records its relationship, the first for a target, so a later add still reuses it as before.
  • Added a test: 50,000 relationships plus a repeated id (the first wins), then 50,000 distinct hyperlinks added, an identical one reused, and the add_new/add interplay.

Blast radius

Only deckcraft-pptx relationship bookkeeping. Ids, order and output are unchanged. RelsOut.items stays public, and the code that fills it directly (kept chart parts) does not call add afterwards.

Also checked: content types are already parsed once per package (ct_cache), and kept chart relationships are already built once per payload (seen_payloads). Neither needed a change.

Checks run

  • cargo fmt -p deckcraft-pptx --check
  • cargo clippy -p deckcraft-pptx --all-targets -- -D warnings
  • cargo test -p deckcraft-pptx (unit, chart_data_labels, the it suite)

Checks not run

  • The full cargo xtask ci

Summary by CodeRabbit

  • Performance
    • Improved relationship lookups and reuse when working with presentations containing many linked resources. This may help large presentations process more efficiently.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

Relationship lookup and reuse now use indexes in place of linear scans. Duplicate relationship IDs resolve to the first item. The added test checks lookup and reuse behavior across 50,000 relationships.

Changes: Relationship Indexing

Layer / File(s) Summary
Indexed relationship operations
crates/pptx/src/opc.rs
Rels looks up IDs through an index that retains the first item for duplicate IDs. RelsOut::add reuses IDs through an index keyed by relationship type, target, and external status. add_new continues to append distinct relationships. A test checks lookup, reuse, and distinction between internal and external relationships across 50,000 relationships.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Suggested reviewers: echelon

Merge Risk: Minimal · up to cab5e

No actionable issue remains from this review; the change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main changes: relationships are indexed by ID on import and by target on export. The raw summary confirms this. Import indexes the relationship ID map, and export indexes by ty…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two main changes: relationships are indexed by ID on import and by target on export. The raw summary confirms this. Import indexes the relationship ID map, and export indexes by type, target, and external status. The title is specific and matches the changeset. It names the export key as target, while the code also keys on type and external status, so the title is slightly narrower than the full key, but it is still a fair summary.

Full details: Docstring Coverage

Explanation

Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 0c00f22 and cab5e55.

Files selected for processing: 1
  • crates/pptx/src/opc.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@dylanmtaylor
dylanmtaylor merged commit 996bb42 into main Nov 4, 2026
9 of 10 checks passed
@dylanmtaylor
dylanmtaylor deleted the fix/sec-pptx-rels-index branch November 4, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant