Attached Files | 37019-wip.diff [^] (3,670 bytes) 2017-10-06 10:29 [Show Content] [Hide Content]diff -r afe00a02a28c src/org/openbravo/mobile/core/login/LabelsComponent.java
--- a/src/org/openbravo/mobile/core/login/LabelsComponent.java Tue Oct 03 20:58:59 2017 +0200
+++ b/src/org/openbravo/mobile/core/login/LabelsComponent.java Fri Oct 06 10:13:44 2017 +0200
@@ -1,6 +1,6 @@
/*
************************************************************************************
- * Copyright (C) 2012-2013 Openbravo S.L.U.
+ * Copyright (C) 2012-2017 Openbravo S.L.U.
* Licensed under the Openbravo Commercial License version 1.0
* You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
* or in the legal folder of this module distribution.
@@ -10,6 +10,8 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.log4j.Logger;
import org.codehaus.jettison.json.JSONArray;
@@ -27,9 +29,17 @@
public class LabelsComponent {
private static final Logger log = Logger.getLogger(LabelsComponent.class);
+ private static Map<String, JSONObject> labelCache = new ConcurrentHashMap<>(1);
+ private static Map<String, JSONObject> listCache = new ConcurrentHashMap<>(1);
+ private static Map<String, String> modDepsCache = new ConcurrentHashMap<>(1);
public static JSONObject getLabels(String languageId, String moduleId) {
try {
+ String cacheKey = getCacheKey(languageId, moduleId);
+ JSONObject cachedValue = labelCache.get(cacheKey);
+ if (cachedValue != null) {
+ return cachedValue;
+ }
String modules = getMobileAppDependantModuleIds(moduleId);
JSONObject labels = new JSONObject();
String hqlLabel = "select message.searchKey, message.messageText "//
@@ -67,6 +77,7 @@
labels.put("languageSk", langSk);
labels.put("languageId", langId);
labels.put("userId", OBContext.getOBContext().getUser().getId());
+ labelCache.put(cacheKey, labels);
return labels;
} catch (Exception e) {
log.error("There was an exception while generating the Mobile labels", e);
@@ -76,6 +87,12 @@
public static JSONObject getLists(String languageId, String moduleId) {
try {
+ String cacheKey = getCacheKey(languageId, moduleId);
+ JSONObject cachedValue = listCache.get(cacheKey);
+ if (cachedValue != null) {
+ return cachedValue;
+ }
+
String modules = getMobileAppDependantModuleIds(moduleId);
JSONObject lists = new JSONObject();
String computedLanguage = getComputedLanguage();
@@ -102,6 +119,7 @@
listValues.put(item);
}
lists.put("languageId", computedLanguage);
+ listCache.put(cacheKey, lists);
return lists;
} catch (Exception e) {
log.error("There was an exception while generating the Mobile reference list", e);
@@ -110,6 +128,10 @@
}
public static String getMobileAppDependantModuleIds(String moduleId) {
+ String cachedValue = modDepsCache.get(moduleId);
+ if (cachedValue != null) {
+ return cachedValue;
+ }
StringBuffer ids = new StringBuffer();
List<Module> dependantModules = new ArrayList<Module>();
@@ -133,9 +155,17 @@
n++;
}
ids.append(")");
+
+ String mods = ids.toString();
+ modDepsCache.put(moduleId, mods);
+
return ids.toString();
}
+ private static String getCacheKey(String languageId, String moduleId) {
+ return languageId + "-" + moduleId;
+ }
+
private static List<Module> getDependantModules(Module module, List<ModuleDependency> allDeps) {
List<Module> moduleList = new ArrayList<Module>();
for (ModuleDependency depModule : allDeps) {
|