I hope you are loading the customerAccountTotalBalances. Here you are loading them for each CustomerAccount and doing sum on the result :(
Instead you should make it part of the query (remove the accessor!)
->withSum('customerAccountTotalBalances as total_balance', 'price')
It is now available on ->total_balance
And you can even use it in the query
->having('total_balance', '>', 0)
https://laravel.com/docs/11.x/eloquent-relationships#other-aggregate-functions