Support » Plugin: Pronamic Google Maps » [PATCH] Huge number of unnecessary meta rows

  • Resolved flynsarmy


    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 );
    		delete_post_meta( $post_id, $meta_key );

    then update the savePost() method replacing all instances of




    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.


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


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


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


    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);


    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.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[PATCH] Huge number of unnecessary meta rows’ is closed to new replies.