refactor(brain): catalog-independent PGCatalogBrain#156
Merged
Conversation
Catalog-independent brains cache cleanly across request boundaries. Catalog reference moves onto the transient CatalogSearchResults (needed there for ZODB prefetch _p_jar access), not onto individual brains. - getURL now uses only zope.globalrequest.getRequest(); no catalog lookup - getObject / _unrestrictedGetObject resolve the traversal root via getSite().getPhysicalRoot() with a request.PARENTS fallback - PGCatalogBrain.__slots__ drops _catalog; __init__ accepts catalog=None for backwards API compatibility but ignores it - Brain tests mock plone.pgcatalog.brain._traversal_root instead of wiring a fake catalog onto the brain Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_catalogfromPGCatalogBrain.__slots__so brains can be cached across request boundaries without carrying per-request referencesgetURLuseszope.globalrequest.getRequest()only — no catalog lookupgetObject/_unrestrictedGetObjectresolve the traversal root viagetSite().getPhysicalRoot()with arequest.PARENTS[-1]fallback (new_traversal_root()module helper)CatalogSearchResults(transient), where ZODB prefetch still needs it for_p_jar__init__(self, row, catalog=None)accepts the kwarg for backwards API compatibility but ignores itWhy
Per-brain catalog references interfere with brain caching and prevent catalog-independent reuse. Addresses the feedback on the prior prefetch work: prefetch belongs on the result set, not on individual brains.
Test plan
plone.pgcatalog.brain._traversal_rootinstead of wiring a fake cataloggetURLviagetRequest()path and the no-request fallback togetPath()🤖 Generated with Claude Code