Commit 1044d1c7 authored by Philipp Hörist's avatar Philipp Hörist

Improve default avatar caching

Caches now also the circle clipping
parent ee7ad12f
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
log = logging.getLogger('gajim.gtk.avatar') log = logging.getLogger('gajim.gtk.avatar')
@lru_cache(maxsize=1024)
def generate_avatar(letters, color, size, scale): def generate_avatar(letters, color, size, scale):
# Get color for nickname with XEP-0392 # Get color for nickname with XEP-0392
color_r, color_g, color_b = color color_r, color_g, color_b = color
...@@ -139,7 +138,9 @@ def get_surface(self, contact, size, scale): ...@@ -139,7 +138,9 @@ def get_surface(self, contact, size, scale):
else: else:
color_string = contact.jid color_string = contact.jid
surface = self._generate_default_avatar(name, color_string, size, scale) letter = self._generate_letter(name)
surface = self._generate_default_avatar(
letter, color_string, size, scale)
self._cache[jid][(size, scale)] = surface self._cache[jid][(size, scale)] = surface
return surface return surface
...@@ -159,7 +160,8 @@ def get_muc_surface(self, account, jid, size, scale): ...@@ -159,7 +160,8 @@ def get_muc_surface(self, account, jid, size, scale):
con = app.connections[account] con = app.connections[account]
name = get_groupchat_name(con, jid) name = get_groupchat_name(con, jid)
surface = self._generate_default_avatar(name, jid, size, scale) letter = self._generate_letter(name)
surface = self._generate_default_avatar(letter, jid, size, scale)
self._cache[jid][(size, scale)] = surface self._cache[jid][(size, scale)] = surface
return surface return surface
...@@ -265,8 +267,9 @@ def _generate_letter(name): ...@@ -265,8 +267,9 @@ def _generate_letter(name):
return letter.capitalize() return letter.capitalize()
return name[0].capitalize() return name[0].capitalize()
def _generate_default_avatar(self, name, color_string, size, scale): @staticmethod
letter = self._generate_letter(name) @lru_cache(maxsize=2048)
def _generate_default_avatar(letter, color_string, size, scale):
color = text_to_color(color_string) color = text_to_color(color_string)
surface = generate_avatar(letter, color, size, scale) surface = generate_avatar(letter, color, size, scale)
surface = clip_circle(surface) surface = clip_circle(surface)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment