WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 21 months ago

#44971 new enhancement

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

Reported by: andfinally Owned by:
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 2 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 (3)

@andfinally
2 years ago

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

#1 @SergeyBiryukov
2 years ago

  • Component changed from Widgets to Administration

#2 @pento
21 months ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.