Merged
Conversation
Use get_actor_url_from_attributed_to() in mastodon_api_account_external_user
to handle both the new ap_actor_id format and legacy id format. Previously,
posts using the new format would fail the string check and return the
subscription user account ("external") instead of the actual actor.
Also optimize convert_actor_to_mastodon_handle() with a static cache and
URL pattern matching for known ActivityPub URL schemes (Mastodon, GoToSocial,
Pleroma, Akkoma) to avoid expensive unindexed guid queries.
- Reblog handler: try attributedTo metadata first (fast path), only fall back to mastodon_api_account filter when preferredUsername is missing - Account handler: use Remote_Actors::get_acct() when ap_actor_id is available to avoid slow guid lookup - Add is_known_activitypub_host() to detect fediverse instances from stored ap_actor posts (single query, cached per request) - Rewrite convert_actor_to_mastodon_handle() to use URL pattern matching on known hosts instead of slow get_by_uri() calls
Test handle conversion for various URL patterns (/@username, /users/, .social TLD, mastodon.* domains, unknown hosts), reblog metadata fast path, and account metadata resolution from attributedTo.
Contributor
Test this PR in WordPress PlaygroundYou can test this pull request directly in WordPress Playground: This will install and activate the plugin with the changes from this PR. |
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
Optimizes the Friends plugin's Mastodon API integration to avoid slow database queries that were causing timeline and account resolution to take seconds per post.
Companion to akirk/enable-mastodon-apps#278.
Changes
attributedTometadata first (fast path), only fall back tomastodon_api_accountfilter whenpreferredUsernameis missing. This avoids a slowget_by_uri()call per reblog.Remote_Actors::get_acct()whenap_actor_idis available, avoiding the slow unindexed guid lookup.get_actor_url_from_attributed_to()instead of manually checking$meta['attributedTo']['id'], which failed for posts using the newap_actor_idformat.is_known_activitypub_host(): queries allap_actorguids once per request (post_type is indexed, no JOINs) and builds a hosts map. Used byconvert_actor_to_mastodon_handle()to determine if a host is a known fediverse instance.convert_actor_to_mastodon_handle(): uses URL pattern matching on known hosts instead of the slowget_by_uri()calls. Handles/@usernameon any domain, and/users/usernameor other 2-segment paths on known hosts (.socialTLD,mastodon.*domains, or hosts found inap_actortable).Test plan