Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Last active Nov 21, 2015
Embed
What would you like to do?
Modern Tribe's The Event Calendar plugin edit event screen improvement.
<?php
/**
* Modern Tribe's The Event Calendar plugin would be much faster in the editing interface
* if it removed the upfront loading of organizers and venues from the select dropdown and
* relied on AJAX loading after initial page load. Additional improvement would be to drop
* the `get_the_title` method when displaying the venue and organizer titles in the list.
* This was tested on a production site with ~4500+ events. Average of 10 attempts time to
* load edit screen prior to modification 47.2 seconds with memory load 290.63mb and
* 18,968 queries. In contrast after modification 16.88 seconds with memory load 217.89mb
* and 155 queries.
*
* The server environment is running middle package on WP Engine. The memory for the site
* is bumped to 512mb. Caching is enabled for assets and objects. CDN is enabled.
*
* Additional points of interest during the screen load is the following calls that occur
* - After cleanup, occasionally `getEventMeta` and `isVenue` is called almost 6000 times each
* - The Events Calendar Pro plugin is active an running.
* - The events tested are not recurring, they are a mix of all day and date with time based.
* - Some events have no organizer, some have one, some have several organizers selected.
*/
// file: the-events-calendar/src/Tribe/Main.php
// line: 1548 replace `$venue_title = wp_kses( get_the_title( $my_venue->ID ), array() );`
$venue_title = wp_kses( $my_venue->post_title, array() );
// line: 1596 replace `$venue_title = wp_kses( get_the_title( $venue->ID ), array() );`
$venue_title = wp_kses( $venue->post_title, array() );
// line: 1638 replace `$organizer_title = wp_kses( get_the_title( $my_organizer->ID ), array() );`
$organizer_title = wp_kses( $my_organizer->post_title, array() );
// line: 1685 replace `$organizer_title = wp_kses( get_the_title( $organizer->ID ), array() );`
$organizer_title = wp_kses( $organizer->post_title, array() );
/**
* Follow up testing reveals some potential areas of improvement. First, the use of
* transients for storing lookup queries for venue and organizer could be beneficial
* to caching for large event sites.
*/
/**
* 2015-11-21 update:
* after discussing with Tribe Support through a pull request I made several adjustments by removing the
* wp_kses method and passing through the object to get_the_title in order to continue to leverage the
* `the_title` filter. Passing the object through reduces all the lookup calls even in a non-cached environment.
* Removal of the kses methods does not resolve the issue of potential tags in the title but ideally that
* would be handled on save vs display of the content. Thus if this case justifies the large majority case
* it would make sense to continue down this path; however, in the case of a large set of venues/organizers
* it might be better suited to allow performance tuning without modifying the plugin code via a filter. As
* identified earlier an AJAX call for this data would be most optimal to shove the processing to later
* stage while the admin page renders.
* see the pull request: https://github.com/moderntribe/the-events-calendar/pull/422
* wp_kses performanace article: https://www.tollmanz.com/wp-kses-performance/
*/
// file: the-events-calendar/src/Tribe/Main.php
// line: 1548 replace `$venue_title = wp_kses( get_the_title( $my_venue->ID ), array() );`
$venue_title = get_the_title( $my_venue );
// line: 1596 replace `$venue_title = wp_kses( get_the_title( $venue->ID ), array() );`
$venue_title = get_the_title( $venue );
// line: 1638 replace `$organizer_title = wp_kses( get_the_title( $my_organizer->ID ), array() );`
$organizer_title = get_the_title( $my_organizer->post_title );
// line: 1685 replace `$organizer_title = wp_kses( get_the_title( $organizer->ID ), array() );`
$organizer_title = get_the_title( $organizer->post_title );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment