From 758912da64f37d4a028ab0adeb7f398ee5cf43c6 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 31 May 2023 14:03:46 +0200 Subject: [PATCH] do not use cache for new followers --- includes/class-mention.php | 2 +- includes/class-scheduler.php | 4 ++-- includes/functions.php | 16 ++++++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/includes/class-mention.php b/includes/class-mention.php index 49f7860..a072bde 100644 --- a/includes/class-mention.php +++ b/includes/class-mention.php @@ -114,7 +114,7 @@ class Mention { * @return string The Inbox-URL */ public static function get_inbox_by_mentioned_actor( $actor ) { - $metadata = get_remote_metadata_by_actor( $actor, true ); + $metadata = get_remote_metadata_by_actor( $actor ); if ( \is_wp_error( $metadata ) ) { return $metadata; diff --git a/includes/class-scheduler.php b/includes/class-scheduler.php index 07926d8..ea1a6e4 100644 --- a/includes/class-scheduler.php +++ b/includes/class-scheduler.php @@ -100,7 +100,7 @@ class Scheduler { $followers = Followers::get_outdated_followers(); foreach ( $followers as $follower ) { - $meta = get_remote_metadata_by_actor( $follower->get_actor() ); + $meta = get_remote_metadata_by_actor( $follower->get_actor(), true ); if ( empty( $meta ) || ! is_array( $meta ) || is_wp_error( $meta ) ) { $follower->set_error( $meta ); @@ -121,7 +121,7 @@ class Scheduler { $followers = Followers::get_faulty_followers(); foreach ( $followers as $follower ) { - $meta = get_remote_metadata_by_actor( $follower->get_actor() ); + $meta = get_remote_metadata_by_actor( $follower->get_actor(), true ); if ( is_tombstone( $meta ) ) { $follower->delete(); diff --git a/includes/functions.php b/includes/functions.php index 2337a7c..423a6ef 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -54,11 +54,12 @@ function get_webfinger_resource( $user_id ) { /** * Requests the Meta-Data from the Actors profile * - * @param string $actor The Actor URL + * @param string $actor The Actor URL. + * @param bool $cached If the result should be cached. * * @return array The Actor profile as array */ -function get_remote_metadata_by_actor( $actor ) { +function get_remote_metadata_by_actor( $actor, $cached = true ) { $pre = apply_filters( 'pre_get_remote_metadata_by_actor', false, $actor ); if ( $pre ) { return $pre; @@ -75,11 +76,14 @@ function get_remote_metadata_by_actor( $actor ) { return $actor; } - $transient_key = 'activitypub_' . $actor; - $metadata = \get_transient( $transient_key ); + // only check the cache if needed. + if ( $cached ) { + $transient_key = 'activitypub_' . $actor; + $metadata = \get_transient( $transient_key ); - if ( $metadata ) { - return $metadata; + if ( $metadata ) { + return $metadata; + } } if ( ! \wp_http_validate_url( $actor ) ) {