Skip to content

Cache RIT Images better #292

@mxmeinhold

Description

@mxmeinhold
Collaborator

This is a bad cache

@lru_cache(maxsize=256)
def get_rit_image(username: str) -> str:
if username:
addresses = [username + '@rit.edu', username + '@g.rit.edu']
for addr in addresses:
url = 'https://gravatar.com/avatar/' + hashlib.md5(addr.encode('utf8')).hexdigest() + '.jpg?d=404&s=250'
try:
gravatar = urllib.request.urlopen(url)
if gravatar.getcode() == 200:
return url
except:
continue
return 'https://www.gravatar.com/avatar/freshmen?d=mp&f=y'

It caches the first call to this function for any given username (up to 256 of them) via functools.lru_cache, which is bad, because it kinda defeats the point of gravatar.

We could do some form of caching, but probably shouldn't. Loading these images lazily in the frontend would probably be much better.

At the very least, please remove the cache so we can stop kicking the pods to have photos update.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuejavascriptPull requests that update Javascript codepythonPull requests that update Python code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mxmeinhold

        Issue actions

          Cache RIT Images better · Issue #292 · ComputerScienceHouse/packet