From b094b196f0ee512c75dc9c255f6770d03a1c1a0f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 1 Aug 2018 09:49:13 +0200 Subject: [PATCH] Added groups information caching. --- .../client/data/helpers/GroupsHelper.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GroupsHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GroupsHelper.java index 9c799ad..6fc980b 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GroupsHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/GroupsHelper.java @@ -22,6 +22,11 @@ import java.util.ArrayList; */ public class GroupsHelper extends BaseHelper { + /** + * Groups information cache + */ + private static ArrayMap mInfoCache = new ArrayMap<>(); + /** * Groups constructor * @@ -40,7 +45,31 @@ public class GroupsHelper extends BaseHelper { */ @Nullable public ArrayMap getInfoMultiple(ArrayList IDs){ - return downloadMultiple(IDs); + + //Process each group to check if its information are available in the cache or not + ArrayList toGet = new ArrayList<>(); + + for(int id : IDs){ + if(!mInfoCache.containsKey(id)) + toGet.add(id); + } + + if(toGet.size() > 0){ + + ArrayMap downloaded = downloadMultiple(toGet); + + if(downloaded == null) + return null; // Can not get information about all the groups + + for(int id : toGet) + mInfoCache.put(id, downloaded.get(id)); + } + + //Extract groups information from cache + ArrayMap list = new ArrayMap<>(); + for(int id : IDs) + list.put(id, mInfoCache.get(id)); + return list; } /**