mozilla-mobile / guardian-vpn-ios

Mozilla VPN for iOS
https://vpn.mozilla.org
Mozilla Public License 2.0
52 stars 16 forks source link

Bugfix/pgios255 prevent duplicate avatar calls #188

Closed connected-rkingsmill closed 4 years ago

connected-rkingsmill commented 4 years ago

Prevent multiple calls to mozillausercontent.com by only getting avatar image when the user's url changes

Paul-Huang-Connected commented 4 years ago

For your consideration :)

Requirement: reduce amount of network calls made to fetch avatar images. The URL to the avatar image changes when a new avatar image is uploaded.

  1. private func downloadAvatar(_ url: URL) can be a part of the GuardianAPI.accountInfo(...) call instead of being done ad-hoc here
  2. When creating a URLRequest, you can customize its cachePolicy to be returnCacheDataElseLoad so that iOS will always check local cache first before making a new network call. In you code change, you essentially created your own cache of the avatar url.