From c32990dff19c17936a6b55085f9b1b513b37e39d Mon Sep 17 00:00:00 2001 From: Marvin W Date: Tue, 11 Jun 2019 14:45:26 +0200 Subject: Ensure avatars are not loaded multiple times --- libdino/src/service/avatar_manager.vala | 10 ++++++++++ libdino/src/service/avatar_storage.vala | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'libdino') diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala index c9c078ab..a47273ee 100644 --- a/libdino/src/service/avatar_manager.vala +++ b/libdino/src/service/avatar_manager.vala @@ -23,6 +23,7 @@ public class AvatarManager : StreamInteractionModule, Object { private HashMap vcard_avatars = new HashMap(Jid.hash_func, Jid.equals_func); private AvatarStorage avatar_storage = new AvatarStorage(get_storage_dir()); private HashMap cached_pixbuf = new HashMap(); + private HashMap> pending_pixbuf = new HashMap>(); private const int MAX_PIXEL = 192; public static void start(StreamInteractor stream_interactor, Database db) { @@ -50,12 +51,21 @@ public class AvatarManager : StreamInteractionModule, Object { if (cached_pixbuf.has_key(hash)) { return cached_pixbuf[hash]; } + if (pending_pixbuf.has_key(hash)) { + pending_pixbuf[hash].add(new SourceFuncWrapper(get_avatar_by_hash.callback)); + yield; + return cached_pixbuf[hash]; + } + pending_pixbuf[hash] = new ArrayList(); Pixbuf? image = yield avatar_storage.get_image(hash); if (image != null) { cached_pixbuf[hash] = image; } else { db.avatar.delete().with(db.avatar.hash, "=", hash).perform(); } + foreach (SourceFuncWrapper sfw in pending_pixbuf[hash]) { + sfw.sfun(); + } return image; } diff --git a/libdino/src/service/avatar_storage.vala b/libdino/src/service/avatar_storage.vala index d6bdd30e..26c98e12 100644 --- a/libdino/src/service/avatar_storage.vala +++ b/libdino/src/service/avatar_storage.vala @@ -33,7 +33,7 @@ public class AvatarStorage : Xep.PixbufStorage, Object { File file = File.new_for_path(Path.build_filename(folder, id)); FileInputStream stream = yield file.read_async(); - uint8 fbuf[100]; + uint8 fbuf[1024]; size_t size; Checksum checksum = new Checksum (ChecksumType.SHA1); -- cgit v1.2.3-70-g09d2