Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache RIT Images better #292

Open
mxmeinhold opened this issue Aug 26, 2021 · 0 comments
Open

Cache RIT Images better #292

mxmeinhold opened this issue Aug 26, 2021 · 0 comments
Labels
good first issue javascript Pull requests that update Javascript code python Pull requests that update Python code

Comments

@mxmeinhold
Copy link
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.

@mxmeinhold mxmeinhold added good first issue python Pull requests that update Python code javascript Pull requests that update Javascript code labels Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue javascript Pull requests that update Javascript code python Pull requests that update Python code
Projects
None yet
Development

No branches or pull requests

1 participant