WP Discourse performing a lot of requests to site.json

I’m working on an integration for a client and I had a tail on the Discourse logs while working on their Wordpress forum.

And this is what I saw coming by (sorry for the odd log format). The IP address is the IP address of the Wordpress server. It is running WP Discourse 2.5.5.

I’ve been looking through the code and I can’t figure out why this is happening.

2024-10-23T06:39:30+00:00|67.225.163.100|5857|0.023|200|GET /site.json HTTP/1.1
2024-10-23T06:39:30+00:00|67.225.163.100|5857|0.022|200|GET /site.json HTTP/1.1
2024-10-23T06:39:30+00:00|67.225.163.100|5857|0.020|200|GET /site.json HTTP/1.1
2024-10-23T06:39:31+00:00|67.225.163.100|5857|0.023|200|GET /site.json HTTP/1.1
2024-10-23T06:39:31+00:00|67.225.163.100|5857|0.024|200|GET /site.json HTTP/1.1
2024-10-23T06:39:31+00:00|67.225.163.100|5857|0.020|200|GET /site.json HTTP/1.1
2024-10-23T06:39:31+00:00|67.225.163.100|5857|0.019|200|GET /site.json HTTP/1.1
2024-10-23T06:39:31+00:00|67.225.163.100|5857|0.022|200|GET /site.json HTTP/1.1
2024-10-23T06:39:31+00:00|67.225.163.100|5857|0.021|200|GET /site.json HTTP/1.1
2024-10-23T06:39:32+00:00|67.225.163.100|5857|0.018|200|GET /site.json HTTP/1.1
2024-10-23T06:39:32+00:00|67.225.163.100|5857|0.018|200|GET /site.json HTTP/1.1
2024-10-23T06:39:32+00:00|67.225.163.100|5857|0.021|200|GET /site.json HTTP/1.1
2024-10-23T06:39:33+00:00|67.225.163.100|5857|0.021|200|GET /site.json HTTP/1.1
2024-10-23T06:39:33+00:00|67.225.163.100|5857|0.024|200|GET /site.json HTTP/1.1
2024-10-23T06:39:33+00:00|67.225.163.100|5857|0.020|200|GET /site.json HTTP/1.1
2024-10-23T06:39:33+00:00|67.225.163.100|5857|0.024|200|GET /site.json HTTP/1.1
2024-10-23T06:39:33+00:00|67.225.163.100|5857|0.021|200|GET /site.json HTTP/1.1
2024-10-23T06:39:33+00:00|67.225.163.100|5857|0.022|200|GET /site.json HTTP/1.1
2024-10-23T06:39:34+00:00|67.225.163.100|5857|0.022|200|GET /site.json HTTP/1.1
2024-10-23T06:39:34+00:00|67.225.163.100|5857|0.023|200|GET /site.json HTTP/1.1
2024-10-23T06:39:34+00:00|67.225.163.100|5857|0.021|200|GET /site.json HTTP/1.1
2024-10-23T06:39:34+00:00|67.225.163.100|662|0.012|429|GET /site.json HTTP/1.1
2024-10-23T06:39:34+00:00|67.225.163.100|662|0.014|429|GET /site.json HTTP/1.1
2024-10-23T06:39:34+00:00|67.225.163.100|662|0.011|429|GET /site.json HTTP/1.1
2 Likes

I imagine it’s coming from this call: wp-discourse/lib/plugin-utilities.php at main · discourse/wp-discourse · GitHub

Which apparently is used in 3 cases:

  • fill the category selector in some form
  • meta box
  • discourse-sidebar

Yeah.
The weird thing is that it is supposed to be cached, and I have no reason to believe that it is not.

$categories = get_transient( 'wpdc_discourse_categories' );
if ( ! empty( $options['publish-category-update'] ) || ! $categories ) {
  $body = $this->discourse_request( '/site.json' );
  if ( is_wp_error( $body ) ) {
    return $body;
  }

  if ( $body->categories ) {

    // removed for brevity

    // Note that setting the cache to 0 will disable transient expiration.
    $category_cache_period = apply_filters( 'wpdc_category_cache_minutes', 10 );
    set_transient( 'wpdc_discourse_categories', $discourse_categories, intval( $category_cache_period ) * MINUTE_IN_SECONDS );

    return $discourse_categories;
  } else {
    return new \WP_Error( 'key_not_found', 'The categories key was not found in the response from Discourse.' );
  }
}

EDIT When I list the transients I do have a key timeout_wpdc_discourse_categories with a value of a timestamp in 5 minutes, but I do not have a wpdc_discourse_categories :thinking:

EDIT 2 set_transient( 'wpdc_discourse_categories', $discourse_categories, intval( $category_cache_period ) * MINUTE_IN_SECONDS ); is returning false. $discourse_categories is correctly filled. Other transients are working.

Update: The transient is simply not saving. It is saving when I json_encode() it.

Also, I am unable to reproduce this on another Wordpress instance, so I’m moving this to support because I believe this is a Wordpress issue. I suspect there might be some kind of security plugin interfering.

1 Like