Author: ashish
Date: Mon Jun 11 13:27:43 2012
New Revision: 1348836
URL: http://svn.apache.org/viewvc?rev=1348836&view=rev
Log:
Applied fix from trunk r1347442.
Set cache flag for findByAnd method calls in PreferenceServices; improved logic
to avoid to run the same query twice when user is not passed.
Note: This is not a bug but not using cache here is really a very serious issue
for performance on production server because the queries are executed at every
page request. We have applied this changes on production server and then
observed the production server activity for about one week and found that now
production server is working fine under heavy load.
Modified:
ofbiz/branches/release10.04/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java
Modified:
ofbiz/branches/release10.04/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/branches/release10.04/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java?rev=1348836&r1=1348835&r2=1348836&view=diff
==============================================================================
---
ofbiz/branches/release10.04/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java
(original)
+++
ofbiz/branches/release10.04/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java
Mon Jun 11 13:27:43 2012
@@ -80,7 +80,7 @@ public class PreferenceServices {
Map<String, Object> userPrefMap = null;
try {
- GenericValue preference =
EntityUtil.getFirst(delegator.findByAnd("UserPreference", fieldMap));
+ GenericValue preference =
EntityUtil.getFirst(delegator.findByAndCache("UserPreference", fieldMap));
if (preference != null) {
userPrefMap = PreferenceWorker.createUserPrefMap(preference);
}
@@ -124,14 +124,16 @@ public class PreferenceServices {
if (UtilValidate.isEmpty(userPrefGroupTypeId)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"getPreference.invalidArgument", locale));
}
- String userLoginId = PreferenceWorker.getUserLoginId(context, true);
+ String userLoginId = PreferenceWorker.getUserLoginId(context, false);
Map<String, Object> userPrefMap = null;
try {
Map<String, String> fieldMap = UtilMisc.toMap("userLoginId",
"_NA_", "userPrefGroupTypeId", userPrefGroupTypeId);
- userPrefMap =
PreferenceWorker.createUserPrefMap(delegator.findByAnd("UserPreference",
fieldMap));
- fieldMap.put("userLoginId", userLoginId);
-
userPrefMap.putAll(PreferenceWorker.createUserPrefMap(delegator.findByAnd("UserPreference",
fieldMap)));
+ userPrefMap =
PreferenceWorker.createUserPrefMap(delegator.findByAndCache("UserPreference",
fieldMap));
+ if (userLoginId != null) {
+ fieldMap.put("userLoginId", userLoginId);
+
userPrefMap.putAll(PreferenceWorker.createUserPrefMap(delegator.findByAndCache("UserPreference",
fieldMap)));
+ }
} catch (GenericEntityException e) {
Debug.logWarning(e.getMessage(), module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"getPreference.readFailure", new Object[] { e.getMessage() }, locale));