My plugin and memory leak

Hi,
on my server I’m running yourls and some plugins like AuthMgrPlus and Shibboleth to manage user authentications.
I wrote a plugin to let the admins see the username of users who shortened URLs: it adds an extra-column named “Owner” on the right.

I’m not experenced on PHP develop so i think some things have gone wrong. Here’s my code:

 if( !defined( 'YOURLS_ABSPATH' ) ) die();

 global $amp_role_assignment;
       //$current_user = $_SERVER['uid'];
      //print_r($_SERVER);

     // Only administrators can see url's owner	
if (  in_array($_SERVER['uid'],$amp_role_assignment['administrator']) ){

// Adds "Owner" column in the html table
yourls_add_filter('table_head_cells', 'aov_table_head_cells');
function aov_table_head_cells($cells) {
        $cells = array(
                'shorturl' => yourls__( 'Short URL' ),
                'longurl'  => yourls__( 'Original URL' ),
                'date'     => yourls__( 'Date' ),
                'ip'       => yourls__( 'IP' ),
                'clicks'   => yourls__( 'Clicks' ),
                'actions'  => yourls__( 'Actions' ),
                'owner'    => yourls__( 'Owner' ),
        );
	return $cells;
}

// Gets owner's from the database 

yourls_add_filter( 'table_add_row_cell_array', 'aov_table_add_row_cell_array');
function aov_table_add_row_cell_array ($cells, $keyword, $url, $title, $ip, $clicks, $timestamp){
	global $ydb;
	$table_db  = YOURLS_DB_TABLE_URL;
	$owner     = $ydb->fetchObjects("select user from $table_db where keyword = '$keyword'");
//	print_r($owner[0]->user);
	$owner 	   = $owner[0]->user;
	$keyword   = yourls_sanitize_keyword($keyword);
	$shorturl  = yourls_link( $keyword );
	$id        = yourls_string2htmlid( $keyword ); // used as HTML #id

        $protocol_warning = '';
        if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) )
        $protocol_warning = yourls_apply_filter( 'add_row_protocol_warning', '<span class="warning" title="' . yourls__( 'Not a common link' ) . '">&#9733;</span>' );

	// Action buttons
	$statlink = yourls_statlink( $keyword );

	$delete_link = yourls_nonce_url( 'delete-link_'.$id,
		yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
	);

	$edit_link = yourls_nonce_url( 'edit-link_'.$id,
		yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
	);

	$actions = array(
		'stats' => array(
			'href'    => $statlink,
			'id'      => "statlink-$id",
			'title'   => yourls_esc_attr__( 'Stats' ),
			'anchor'  => yourls__( 'Stats' ),
		),
		'share' => array(
			'href'    => '',
			'id'      => "share-button-$id",
			'title'   => yourls_esc_attr__( 'Share' ),
			'anchor'  => yourls__( 'Share' ),
			'onclick' => "toggle_share('$id');return false;",
		),
		'edit' => array(
			'href'    => $edit_link,
			'id'      => "edit-button-$id",
			'title'   => yourls_esc_attr__( 'Edit' ),
			'anchor'  => yourls__( 'Edit' ),
			'onclick' => "edit_link_display('$id');return false;",
		),
		'delete' => array(
			'href'    => $delete_link,
			'id'      => "delete-button-$id",
			'title'   => yourls_esc_attr__( 'Delete' ),
			'anchor'  => yourls__( 'Delete' ),
			'onclick' => "remove_link('$id');return false;",
		)
	);
	$action_links = '';
	foreach( $actions as $key => $action ) {
		$onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ;
		$action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>',
			$action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor']
		);
	}
	$action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp );
	// Row cells: the array
	$cells = array(
		'keyword' => array(
			'template'      => '<a href="%shorturl%">%keyword_html%</a>',
			'shorturl'      => yourls_esc_url( $shorturl ),
			'keyword_html'  => yourls_esc_html( $keyword ),
		),
		'url' => array(
			'template'      => '<a href="%long_url%" title="%title_attr%">%title_html%</a><br/><small>%warning%<a href="%long_url%">%long_url_html%</a></small>',
			'long_url'      => yourls_esc_url( $url ),
			'title_attr'    => yourls_esc_attr( $title ),
			'title_html'    => yourls_esc_html( yourls_trim_long_string( $title ) ),
			'long_url_html' => yourls_esc_html( yourls_trim_long_string( $url ) ),
			'warning'       => $protocol_warning,
		),
		'timestamp' => array(
			'template' => '<span class="timestamp" aria-hidden="true">%timestamp%</span> %date%',
            'timestamp' => $timestamp,
			'date'     => yourls_date_i18n( yourls_get_datetime_format('M d, Y H:i'), yourls_get_timestamp( $timestamp )),
		),
		'ip' => array(
			'template' => '%ip%',
			'ip'       => $ip,
		),
		'clicks' => array(
			'template' => '%clicks%',
			'clicks'   => yourls_number_format_i18n( $clicks, 0, '', '' ),
		),
		'actions' => array(
			'template' => '%actions% <input type="hidden" id="keyword_%id%" value="%keyword%"/>',
			'actions'  => $action_links,
			'id'       => $id,
			'keyword'  => $keyword,
		),
		'owner' => array(
			'template' => '%owner%',
			'owner'    => $owner,
		),
	);
	return $cells; 
}
   }

The variable $amp_role_assignment is an array defined in user/config.php containing the admininistrators’ “uid”.
My problem is the memory usage, i noticed a slow increment of RAM usage sawtooth-shape.
I tried profiling the code and it seems my plugin that hooks “table_add_row_cell_array” is very memory-expensive.

Finally from terminal running “top” you can see “mysqld” on the top of memory usage.

Can someone help me figure out what i’m doing wrong?

Thank you very much,
EC