in user_relationships load the first line of the function declares
static $relationships = array();
This suggests that the author intends to cache query results so the same query doesn't get run multiple times on a singe page load. This is a noble intention but it seems that the code doesn't deliver.
As you will notice in the attached screenshot the query was run 20 times in this page load, and all previous page loads as well.
In the function the data in
$relationships is used if the first argument
$param is an integer, but if it is not the database is queried and the results are not stored back in
$relationships for further use. In addition later in the function, the
$relationships array is reset so even if there were some data stored there it is lost.