do not use cache for new followers

This commit is contained in:
Matthias Pfefferle 2023-05-31 14:03:46 +02:00
parent 084f108161
commit 758912da64
3 changed files with 13 additions and 9 deletions

View file

@ -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;

View file

@ -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();

View file

@ -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 ) ) {