Avatar updates for users who aren't followed by anyone

Here’s my problem.

  1. I receive a reply to a post of someone who I follow. So I fetch the actor object for whoever made the reply and store it in my database.
  2. The user who made the reply changes their avatar.
  3. I don’t receive anything because no one on my instance follows that user.
  4. When I try to load the avatar using the URL I have stored, I get a 404 because it no longer exists.

I already process the Update{Person} by first checking that the actor matches the user being updated and then simply overwrite whatever I have stored, but I don’t receive any Update activities for those users in the first place.

How does everyone else solve this?

so, mastodon does two things differently that may help:

  1. we cache all images locally for privacy reasons, which means we never have the 404 problem

  2. when receiving an activity, we refetch the user’s profile (including caching the avatar) if it’s been a few days since we’ve last done so.

the combination of these two things mean avatars never get seriously out of date, and for the time period where they are out of date, we have the last cached value to fall back on.

I cache them too now, but I do so lazily to save space so it’s still possible for the user to change the avatar after being fetched but before that URL is followed. I also delete old files from my cache. I could probably refetch the user whenever I get 404 tho :thinking:

I don’t have a solution for the problem of not sending the update to everybody in the world who might have a copy of this record, but for the sake of consistency and resolving race conditions/conflicts all Update activities have an updated time. Additionally the profile photo has its own updated time so any time you fetch the record you can determine if it’s a different photo or if you can keep the one you already have. Since nobody else does this we have to fetch the unchanged photo repeatedly anyway, but we’re keeping the updated timestamps on the photo and the actor record anyway - because it’s the right thing to do. The mere presence of an updated timestamp on the photo means that we’ll know if it didn’t change and save an unnecessary network fetch.