Make WordPress Core

Opened 6 years ago

Last modified 5 months ago

#44971 accepted enhancement

Enable WP_Community_Events to find cached events even if it's instantiated without a user location

Reported by: andfinally's profile andfinally Owned by: pbearne's profile pbearne
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch
Focuses: performance Cc:

Description

The "WordPress Events and News" dashboard widget in wp-admin makes requests to the http://api.wordpress.org/events/1.0/ endpoint for details about WordPress community events in a particular location. The class that powers the widget caches the event data for a location in a transient, using the user's IP address as the key.

At the moment, the localisation function that retrieves this cached data for the dashboard JS, wp_localize_community_events, relies on the fact that the ajax request handler that fetches it, wp_ajax_get_community_events, saves the user's last known location as a user option.

We'd like to show the community events in Calypso too. We've created an endpoint on public-api.wordpress.com (D18510-code) which instantiates WP_Community_Events and fetches the events. We're not persisting the user's last known location, so we're not generally passing a location array to the constructor. To avoid putting too much pressure on the api.wordpress.org endpoint, we'd like to make sure the class's get_cached_events method checks if there are cached events for the user's network IP before it makes a request to the API.

We have a workaround for this in our endpoint (D18510-code), which calls get_unsafe_client_ip to create a location for the user if none is provided in search params; but it seems to make more sense to enable the class to handle this case.

WP_Community_Events currently tries to retrieve cached events before it makes a request to the API. If nothing's found in the cache, it calls get_unsafe_client_ip before making the request. This patch moves that call to before the cache search, so that even if the class is instantiated without a location, it'll still be able to find any events cached for the user's current IP.

Attachments (1)

WP_Community_Events.patch (1.3 KB) - added by andfinally 6 years ago.
Change to enable WP_Community_Events to find cached events when no location is passed to the constructor

Download all attachments as: .zip

Change History (6)

@andfinally
6 years ago

Change to enable WP_Community_Events to find cached events when no location is passed to the constructor

#1 @SergeyBiryukov
6 years ago

  • Component changed from Widgets to Administration

#2 @pento
6 years ago

  • Version trunk deleted

This ticket was mentioned in PR #6891 on WordPress/wordpress-develop by @pbearne.


5 months ago
#3

This commit introduces support for dealing with partially anonymized IP addresses. A new property, 'unsafe_client_ip' has been added, which is computed and assigned in the 'get_events' method. This value is then used to assign the 'user_location' property, if it's not already set, and is passed to the 'get_request_args' method.

#4 @pbearne
5 months ago

  • Owner set to pbearne
  • Status changed from new to accepted

#5 @pbearne
5 months ago

refreshed patch

Note: See TracTickets for help on using tickets.