Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@ exclude_patterns:
- tests/
- vendor/
- node_modules/
- build/
- "**.min.css"
- "**.min.js"
- "js/jquery-ui-classic.css"
- "js/jquery-ui-fresh.css"

prepare:
fetch:
- "https://raw.githubusercontent.com/bu-ist/coding-standards/master/code-climate-rule-sets/.eslintrc"
- "https://raw.githubusercontent.com/bu-ist/coding-standards/master/code-climate-rule-sets/.eslintignore"
- "https://raw.githubusercontent.com/bu-ist/coding-standards/master/code-climate-rule-sets/.mdlrc"
- "https://raw.githubusercontent.com/bu-ist/coding-standards/master/code-climate-rule-sets/markdown.rb"

plugins:
csslint:
enabled: false
Expand All @@ -34,6 +28,9 @@ plugins:
enabled: true
markdownlint:
enabled: true
checks:
MD013:
enabled: false
phpcodesniffer:
enabled: true
config:
Expand Down
28 changes: 20 additions & 8 deletions bu-navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Author: Boston University (IS&T)
* Author URI: http://sites.bu.edu/web/
* Description: Provides alternative navigation elements designed for blogs with large page counts
* Version: 1.3.3
* Version: 1.3.6
* Text Domain: bu-navigation
* Domain Path: /languages
* License: GPL2+
Expand Down Expand Up @@ -94,7 +94,7 @@ class BU_Navigation_Plugin {
*
* @var string
*/
const VERSION = '1.3.3';
const VERSION = '1.3.6';

/**
* Plugin class constructor.
Expand Down Expand Up @@ -124,17 +124,29 @@ public function register_hooks() {
}

/**
* Calls wp_cache_add_non_persistent_groups()
* Object cache group configuration for the navigation tree.
*
* Calling wp_cache_add_non_persistent_groups() doesn't appear to do anything
* in modern WordPress?
* The 'bu-navigation' group caches the section/membership structure built by
* load_sections() (see composer-includes/bu-navigation-core-widget/src/data-model.php).
* It is intentionally left PERSISTENT (Redis-backed in production) rather than
* registered non-persistent.
*
* This is safe by construction: the cached payload is order- and status-independent
* parent->children membership only, and its cache key is version-stamped on core's
* 'posts' last_changed value (bumped by clean_post_cache() on every post
* insert/update/delete), so a stale entry is orphaned rather than served. Publication
* status, menu_order ordering, and nav meta are all applied downstream on the uncached
* get_nav_posts() query, so they are never served from this cache.
*
* Previously this method registered the group non-persistent. On production (where an
* object cache is active) that defeated cross-request caching, forcing the expensive
* GROUP_CONCAT/GROUP BY wp_posts scan to run on nearly every front-end render under
* crawler concurrency. Leaving the group persistent removes that scan from the common
* case while preserving the existing per-request invalidation behavior.
*
* @return void
*/
public function add_cache_groups() {
if ( function_exists( 'wp_cache_add_non_persistent_groups' ) ) {
wp_cache_add_non_persistent_groups( array( 'bu-navigation' ) );
}
}

/**
Expand Down
12 changes: 9 additions & 3 deletions composer-includes/bu-navigation-core-widget/src/data-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ function load_sections( $post_types = array( 'page' ), $include_links = true ) {
wp_cache_set( 'last_changed', $last_changed, 'posts' );
}

$cache_key = 'all_sections:' . md5( serialize( $post_types ) . ":$last_changed" );
// Scope the key to the current site. The 'bu-navigation' group is Redis-backed
// (persistent) in production, and although the object cache prefixes non-global
// group keys by blog, including the blog id here guarantees per-site isolation on
// multisite regardless of the drop-in's behavior.
$cache_key = 'all_sections:' . get_current_blog_id() . ':' . md5( serialize( $post_types ) . ":$last_changed" );
if ( $all_sections = wp_cache_get( $cache_key, 'bu-navigation' ) ) {
return $all_sections;
}
Comment on lines +94 to 97
Expand All @@ -105,8 +109,10 @@ function load_sections( $post_types = array( 'page' ), $include_links = true ) {

$all_sections = transform_rows( $rows );

// Cache results.
wp_cache_set( $cache_key, $all_sections, 'bu-navigation' );
// Cache results. The version-stamped key (posts 'last_changed') is the primary
// invalidation; the explicit TTL is a self-healing backstop in case a membership
// change ever bypasses clean_post_cache() (e.g. a direct $wpdb write or import).
wp_cache_set( $cache_key, $all_sections, 'bu-navigation', DAY_IN_SECONDS );

return $all_sections;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function bu_navigation_widget_<?php echo $this->number; ?>_validate(e)

function bu_navigation_widget_<?php echo $this->number; ?>_title_changed()
{
var is_static = jQuery('#<?php echo $this->get_field_id('navigation_title_static');?>').attr('checked');
var is_static = jQuery('#<?php echo $this->get_field_id('navigation_title_static');?>').prop('checked');

if (is_static) {
jQuery(this).siblings('input.only-if-static').attr('disabled', false);
Expand Down
10 changes: 4 additions & 6 deletions js/bu-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ bu.plugins.navigation = {};
// Refresh post status badges (recursively)
// @todo move to callback
if (c.showStatuses) {
$node.find('li').andSelf().each(function (){
$node.find('li').addBack().each(function (){ /* CHANGE: .andSelf() -> .addBack() */
setStatusBadges($(this));
});
}
Expand Down Expand Up @@ -1074,10 +1074,8 @@ bu.plugins.navigation = {};
};

// Prevent default right click behavior
$tree.bind('loaded.jstree', function(e,data) {

$tree.undelegate('a', 'contextmenu.jstree');

$tree.on('loaded.jstree', function(e, data) {
$tree.off('contextmenu.jstree', 'a');
});

// Append options menu to each node
Expand Down Expand Up @@ -1109,7 +1107,7 @@ bu.plugins.navigation = {};
// jstree contextmenu plugin
var currentMenuTarget = null;

$tree.delegate(".edit-options", "click", function (e) {
$tree.on('click', '.edit-options', function (e) {
e.preventDefault();
e.stopPropagation();

Expand Down
2 changes: 1 addition & 1 deletion js/bu-navigation.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ if ((typeof bu === 'undefined') ||
// Clear dialog
$(this.ui.urlField).attr("value", "");
$(this.ui.labelField).attr("value", "");
$(this.ui.targetSameField).attr("checked", "checked");
$(this.ui.targetNewField).removeAttr("checked");
$(this.ui.targetSameField).prop("checked", true);
$(this.ui.targetNewField).prop("checked", false);

this.data.currentLink = null;

Expand Down
2 changes: 1 addition & 1 deletion js/manage.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading