WordPress.org

Ready to get started?Download WordPress

Forums

Pronamic Google Maps
[resolved] [PATCH] Huge number of unnecessary meta rows (2 posts)

  1. flynsarmy
    Member
    Posted 1 year ago #

    I was looking into why my database was so huge (600MB) and discovered it was mostly due to Pronamic Google Maps generating like 10 rows per post, most of which were empty. There is no need for PGM to add meta rows if there is no data to enter so I've whipped up a patch to fix this:

    In /pronamic-google-maps/classes/Pronamic/Google/Maps/Admin.php add:

    /**
     * Only store post meta when there is meta to store
     */
    
    public static function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '')
    {
    	if ( $meta_value )
    		update_post_meta( $post_id, $meta_key, $meta_value, $prev_value );
    	else
    		delete_post_meta( $post_id, $meta_key );
    }

    then update the savePost() method replacing all instances of

    update_post_meta

    with

    self::update_post_meta

    This takes care of most of the fields but we're still stuck with the following in every post:

    _pronamic_google_maps_active = false
    _pronamic_google_maps_map_type = roadmap
    _pronamic_google_maps_zoom = 7

    We can use the defaults in Pronamic_Google_Maps_Maps::getMetaData() to our advantage here. We don't need to store data if that data is equal to a default.

    Change

    self::update_post_meta($postId, Pronamic_Google_Maps_Post::META_KEY_ACTIVE, $active ? 'true' : 'false');

    to

    self::update_post_meta($postId, Pronamic_Google_Maps_Post::META_KEY_ACTIVE, $active ? 'true' : '');

    Change

    self::update_post_meta($postId, Pronamic_Google_Maps_Post::META_KEY_MAP_TYPE, $mapType);

    to

    self::update_post_meta($postId, Pronamic_Google_Maps_Post::META_KEY_MAP_TYPE, $mapType != Pronamic_Google_Maps_Maps::MAP_TYPE_DEFAULT ? $mapType : '');

    And finally change

    self::update_post_meta($postId, Pronamic_Google_Maps_Post::META_KEY_ZOOM, $zoom);

    to

    self::update_post_meta($postId, Pronamic_Google_Maps_Post::META_KEY_ZOOM, $zoom != Pronamic_Google_Maps_Maps::MAP_ZOOM_DEFAULT ? $zoom : '');

    That's it. After implimenting this patch and deleting all empty pronamic rows in my DB (which was almost all of them) I experienced a pretty massive performance boost.

    http://wordpress.org/extend/plugins/pronamic-google-maps/

  2. Remco Tolsma
    Member
    Plugin Author

    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.