[wp-trac] [WordPress Trac] #44971: Enable WP_Community_Events to find cached events even if it's instantiated without a user location

WordPress Trac noreply at wordpress.org
Thu Sep 20 13:59:25 UTC 2018


#44971: Enable WP_Community_Events to find cached events even if it's instantiated
without a user location
-------------------------+-----------------------------
 Reporter:  andfinally   |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Widgets      |    Version:  trunk
 Severity:  normal       |   Keywords:  has-patch
  Focuses:  performance  |
-------------------------+-----------------------------
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44971>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list