Skip to content

Use the named_partial selector in DocumentElement::hasContent() - #881

Open
Amoifr wants to merge 1 commit into
minkphp:masterfrom
Amoifr:feature-880-hascontent-named-partial
Open

Use the named_partial selector in DocumentElement::hasContent()#881
Amoifr wants to merge 1 commit into
minkphp:masterfrom
Amoifr:feature-880-hascontent-named-partial

Conversation

@Amoifr

@Amoifr Amoifr commented Aug 18, 2026

Copy link
Copy Markdown

Extracted from #880, where @aik099 suggested it as a standalone change (point 3).

hasContent() only needs a boolean answer. With the named selector, ElementFinder first tries named_exact and falls back to named_partial, so a miss on the exact match costs an extra driver query. Anything matched by named_exact is also matched by named_partial, so querying named_partial directly returns the same result with a single driver query.

Related to #880.

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.56%. Comparing base (9b08f62) to head (8c9316d).

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #881   +/-   ##
=========================================
  Coverage     98.56%   98.56%           
  Complexity      389      389           
=========================================
  Files            24       24           
  Lines           909      909           
=========================================
  Hits            896      896           
  Misses           13       13           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Comment thread src/Element/DocumentElement.php Outdated
Comment on lines +49 to +51
// anything matched by the "named_exact" selector is also matched by "named_partial",
// so checking "named_partial" directly gives the same result as "named" while
// saving the extra driver query the exact-then-partial fallback would make

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this comment because it's more about historical context (why we changed this) instead of explaining what happens.

As for the "what happens" part, the code itself is self-explanatory: we're looking for a content on a page, and of course we want to sub-match.

Historically the named selector was always about sub-matching, and the exact match was introduced later on.

@Amoifr
Amoifr force-pushed the feature-880-hascontent-named-partial branch from 2ce9af8 to 8c9316d Compare August 19, 2026 12:32
@Amoifr

Amoifr commented Aug 19, 2026

Copy link
Copy Markdown
Author

Done, comment removed. You're right that the code says it all on its own, the history lesson belongs in the PR, not the file. Thanks for the review @aik099!

@aik099

aik099 commented Aug 20, 2026

Copy link
Copy Markdown
Member

Looks good to me. @stof , could be merged?

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.

2 participants