Deduplicate and optimize the collection classes#3527
Draft
pfefferle wants to merge 9 commits into
Draft
Conversation
Persist() attached an anonymous akismet_comment_nonce filter that was never removed, leaking a closure per federated comment and forcing Akismet's nonce check to 'inactive' for every later comment in the request. Use a named method and a try/finally so all four temporary filters are restored on every path. Claude-Session: https://claude.ai/code/session_01HDA9QR3bJoqM7NhnhT1whg
Extract the copy-pasted patterns across the CPT-backed collections into six composable traits (recipients, guid lookup, KSES-safe insert, object title, paginated query, purge) using late static binding, keeping the static call sites unchanged. Collapse Followers::get_inboxes into a single JOIN, replace a sloppy scheme regex with wp_parse_url, harden the actor serialization filter toggle to restore only the filters it removed, and drop deprecated meta_key query args. Claude-Session: https://claude.ai/code/session_01HDA9QR3bJoqM7NhnhT1whg
Split Interactions::activity_to_comment into prepare_local_comment_data, prepare_remote_comment_data, and prepare_remote_comment_meta helpers, and funnel Remote_Actors create/update through a single persist() method so the KSES-safe insert/update path lives in one place. Claude-Session: https://claude.ai/code/session_01HDA9QR3bJoqM7NhnhT1whg
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.
Proposed changes:
Refactors
includes/collection/to remove duplication and cut complexity, keeping every public call site identical (composable traits via late static binding, static shape retained).Interactions::persist()attached an anonymousakismet_comment_noncefilter it never removed, leaking a closure per federated comment and forcing Akismet's nonce check toinactivefor every later comment in the same request. Now a named method plustry/finallyrestores all four temporary filters on every path.query()+get_by_authority(), object-title derivation, guid lookup, KSES-safe insert, and the batched purge loop.Followers::get_inboxescollapses a two-step query into a single JOIN (runs on every federation send).Remote_Actorsactor serialization now suspends and restores only the mention/hashtag/link filters that were actually registered, at their original priority (fixes an unconditional re-add edge).Actors::get_id_by_resourcereplaces a sloppy scheme regex withwp_parse_url().Remote_Posts::get_by_remote_actor_idswaps deprecatedmeta_key/meta_valuefor ameta_query(drops two PHPCS suppressions).Net roughly −435 lines across the collection classes, plus six small trait files.
With_Guid_Lookupalso drops a latent double-escape inRemote_Actors::get_by_uri(it ranesc_sql()insideprepare()), standardizing on the sameesc_url_rawnormalization used at write time.Other information:
New regression test asserts the comment filters/actions are fully restored after
persist().Testing instructions:
npm run env-test(2760 tests green).composer lint(clean).trunk:Changelog entry
Changelog entry for the Akismet fix is included in the branch (
.github/changelog/restore-akismet-nonce-after-federated-comment); the rest is internal refactor.