Yes the motivation was we noticed we were spending way too much CPU time generating avatars… the avatars.discourse.org is a free service behind CloudFlare CDN to speed up all Discourse instances.
I had to disable the service temporarily, at least until I can figure out a reliable way to parse the JSON returned by the /users/<USERNAME>.json API endpoint, to determine whether a user has provided their own avatar.
The value returned by $json->user->avatar_template is not in a consistent format. If the user has a letter avatar, the value is https://avatars.discourse.org/letter/r/7cd45c/{size}.png, but if the user has specified their own avatar, the format is /user_avatar/<SITENAME>/<USERNAME>/{size}/35_1.png.
I’ll need to figure out a way to determine when to append the domain name (we use the API to show avatars in Wordpress).