Making WordPress.org


Ignore:
Timestamp:
02/22/2016 08:50:25 PM (11 years ago)
Author:
ocean90
Message:

Rosetta, Roles: Improve performance of the edit page.

  • When searching filter the sub-projects collection directly and re-render the list once. Previously a CSS class was added/removed and thus every item was re-rendered. H/t adamsilverstein.
  • Only render the first 100 sub-projects of a project. The others can be revealed through a search.
  • Add an Ajax handler for the projects data and store the JSON data in browser's local storage.

See #1590.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php

    r2523 r2544  
    7777                add_action( 'translation_editor_added', array( $this, 'update_wporg_profile_badge' ) );
    7878                add_action( 'translation_editor_removed', array( $this, 'update_wporg_profile_badge' ) );
     79
     80                add_action( 'wp_ajax_rosetta-get-projects', array( $this, 'ajax_rosetta_get_projects' ) );
    7981        }
    8082
    … …  
    619621         */
    620622        private function render_edit_translation_editor( $user_id ) {
     623                global $wpdb;
     624
     625                $project_access_list = $this->get_users_projects( $user_id );
     626
     627                $last_updated = $wpdb->get_var( 'SELECT meta_value FROM translate_meta WHERE object_type = "gp_option" AND meta_key = "wporg_projects_last_updated"' );
     628
     629                wp_localize_script( 'rosetta-roles', '_rosettaProjectsSettings', array(
     630                        'l10n' => array(
     631                                'searchPlaceholder' => esc_attr__( 'Search...', 'rosetta' ),
     632                        ),
     633                        'lastUpdated' => $last_updated,
     634                        'accessList' => $project_access_list,
     635                ) );
     636
     637                $feedback_message = $this->get_feedback_message();
     638
     639                require __DIR__ . '/views/edit-translation-editor.php';
     640        }
     641
     642        /**
     643         * Ajax handler for retrieving projects.
     644         */
     645        public function ajax_rosetta_get_projects() {
    621646                $projects = $this->get_translate_projects();
    622647                $project_tree = $this->get_project_tree( $projects, 0, 1 );
    … …  
    632657                $project_tree = array_values( $project_tree );
    633658
    634                 $project_access_list = $this->get_users_projects( $user_id );
    635 
    636                 wp_localize_script( 'rosetta-roles', '_rosettaProjectsSettings', array(
    637                         'l10n' => array(
    638                                 'searchPlaceholder' => esc_attr__( 'Search...', 'rosetta' ),
    639                         ),
    640                         'data' => $project_tree,
    641                         'accessList' => $project_access_list,
    642                 ) );
    643 
    644                 $feedback_message = $this->get_feedback_message();
    645 
    646                 require __DIR__ . '/views/edit-translation-editor.php';
     659                ob_start( 'ob_gzhandler' ); // Compress JSON.
     660                wp_send_json_success( $project_tree );
    647661        }
    648662
Note: See TracChangeset for help on using the changeset viewer.