diff --git a/com.openexchange.server/src/com/openexchange/groupware/contexts/impl/LocalCachingContextStorage.java b/com.openexchange.server/src/com/openexchange/groupware/contexts/impl/LocalCachingContextStorage.java index b93d81e3614244a699aa13ae8505946d7a341768..ed268bdf0c25d452b381d9d5ee036a2fc1e14b31 100644 --- a/com.openexchange.server/src/com/openexchange/groupware/contexts/impl/LocalCachingContextStorage.java +++ b/com.openexchange.server/src/com/openexchange/groupware/contexts/impl/LocalCachingContextStorage.java @@ -215,7 +215,7 @@ public class LocalCachingContextStorage extends ContextStorage { Integer contextId = contextIdCache.getIfPresent(loginInfo); if (contextId == null) { try { - contextId = contextIdCache.get(loginInfo, this::loadContextByLoginInfo); + contextId = contextIdCache.get(loginInfo, l0ginInfo -> loadContextByLoginInfo(l0ginInfo, false)); } catch (OXRuntimeException e) { // NOSONARLINT throw e.getException(); } @@ -227,10 +227,11 @@ public class LocalCachingContextStorage extends ContextStorage { * Loads the context by given login info. * * @param loginInfo The login info to load by + * @param populateContextCache <code>true</code> to populate context cache; otherwise <code>false</code> * @return The identifier of the associated context or {@link ContextStorage#NOT_FOUND} if there is none * @throws OXRuntimeException If retrieval fails */ - private Integer loadContextByLoginInfo(String loginInfo) { + private Integer loadContextByLoginInfo(String loginInfo, boolean populateContextCache) { try { ContextExtended context = persistentImpl.getContext(loginInfo); if (null == context) { @@ -238,7 +239,9 @@ public class LocalCachingContextStorage extends ContextStorage { } triggerUpdate(context, UpdateBehavior.NONE); Integer contextId = I(context.getContextId()); - contextCache.put(contextId, context); + if (populateContextCache) { + contextCache.put(contextId, context); + } return contextId; } catch (OXException e) { throw new OXRuntimeException(e); @@ -250,7 +253,7 @@ public class LocalCachingContextStorage extends ContextStorage { ContextExtended context = contextCache.getIfPresent(I(contextId)); if (context == null) { try { - context = contextCache.get(I(contextId), cid -> loadContextById(cid.intValue(), updateBehavior)); + context = contextCache.get(I(contextId), cid -> loadContextById(cid.intValue(), updateBehavior, false)); } catch (OXRuntimeException e) { // NOSONARLINT throw e.getException(); } @@ -262,15 +265,16 @@ public class LocalCachingContextStorage extends ContextStorage { * Loads the context by given identifier. * * @param contextId The context identifier - * @param updateBehavior The update behavior to obey + * @param updateBehavior The update behavior to obey contextIdCache + * @param populateContextIdCache <code>true</code> to populate login-info-2-context-identifier cache; otherwise <code>false</code> * @return The context * @throws OXRuntimeException If retrieval fails */ - private ContextExtended loadContextById(int contextId, UpdateBehavior updateBehavior) { + private ContextExtended loadContextById(int contextId, UpdateBehavior updateBehavior, boolean populateContextIdCache) { try { ContextExtended context = persistentImpl.loadContext(contextId); triggerUpdate(context, updateBehavior); - String[] loginInfo = context.getLoginInfo(); + String[] loginInfo = populateContextIdCache ? context.getLoginInfo() : null; if (loginInfo != null) { Integer iContextId = I(contextId); for (String li : loginInfo) { diff --git a/com.openexchange.server/src/com/openexchange/groupware/ldap/LocalCachingUserStorage.java b/com.openexchange.server/src/com/openexchange/groupware/ldap/LocalCachingUserStorage.java index e7464a1838f25132fe674fbe9c9974e7d7bfa2c9..24d33ca91efef5c459a882d4f1b169c613ddde3c 100644 --- a/com.openexchange.server/src/com/openexchange/groupware/ldap/LocalCachingUserStorage.java +++ b/com.openexchange.server/src/com/openexchange/groupware/ldap/LocalCachingUserStorage.java @@ -212,7 +212,7 @@ public class LocalCachingUserStorage extends UserStorage { CachedUser user = userCache.getIfPresent(key); if (user == null) { try { - user = userCache.get(key, this::loadUserById); + user = userCache.get(key, k -> loadUserById(key, false)); } catch (OXRuntimeException e) { // NOSONARLINT throw e.getException(); } @@ -224,13 +224,14 @@ public class LocalCachingUserStorage extends UserStorage { * Loads the user by given identifier. * * @param uac The user and context identifier + * @param populateLoginCache <code>true</code> to populate login-2-user cache; otherwise <code>false</code> * @return The loaded user * @throws OXRuntimeException If retrieval fails */ - private CachedUser loadUserById(UserAndContext uac) { + private CachedUser loadUserById(UserAndContext uac, boolean populateLoginCache) { try { User user = delegate.getUser(uac.getUserId(), uac.getContextId()); - String loginInfo = user.getLoginInfo(); + String loginInfo = populateLoginCache ? user.getLoginInfo() : null; if (loginInfo != null) { logins2UserCache.put(new ContextIdAndString(uac.getContextId(), loginInfo), I(user.getId())); } @@ -246,7 +247,7 @@ public class LocalCachingUserStorage extends UserStorage { CachedUser user = userCache.getIfPresent(key); if (user == null) { try { - user = userCache.get(key, uac -> loadUserById(uac, context, con)); + user = userCache.get(key, uac -> loadUserById(uac, context, false, con)); } catch (OXRuntimeException e) { // NOSONARLINT throw e.getException(); } @@ -259,14 +260,15 @@ public class LocalCachingUserStorage extends UserStorage { * * @param uac The user and context identifier * @param context The given context + * @param populateLoginCache <code>true</code> to populate login-2-user cache; otherwise <code>false</code> * @param con The connection to use * @return The loaded user * @throws OXRuntimeException If retrieval fails */ - private CachedUser loadUserById(UserAndContext uac, Context context, Connection con) { + private CachedUser loadUserById(UserAndContext uac, Context context, boolean populateLoginCache, Connection con) { try { User user = delegate.loadIfAbsent(uac.getUserId(), getEffectiveContext(uac.getContextId(), context), con); - String loginInfo = user.getLoginInfo(); + String loginInfo = populateLoginCache ? user.getLoginInfo() : null; if (loginInfo != null) { logins2UserCache.put(new ContextIdAndString(uac.getContextId(), loginInfo), I(user.getId())); } @@ -303,7 +305,7 @@ public class LocalCachingUserStorage extends UserStorage { CachedUser user = userCache.getIfPresent(key); if (user == null) { try { - user = userCache.get(key, this::loadUserById); + user = userCache.get(key, k -> loadUserById(k, false)); } catch (OXRuntimeException e) { // NOSONARLINT throw e.getException(); } @@ -317,7 +319,7 @@ public class LocalCachingUserStorage extends UserStorage { CachedUser user = userCache.getIfPresent(key); if (user == null) { try { - user = userCache.get(key, uac -> loadUserById2(uac, ctx, con)); + user = userCache.get(key, uac -> loadUserById2(uac, ctx, false, con)); } catch (OXRuntimeException e) { // NOSONARLINT throw e.getException(); } @@ -330,14 +332,15 @@ public class LocalCachingUserStorage extends UserStorage { * * @param uac The user and context identifier * @param context The given context + * @param populateLoginCache <code>true</code> to populate login-2-user cache; otherwise <code>false</code> * @param con The connection to use * @return The loaded user * @throws OXRuntimeException If retrieval fails */ - private CachedUser loadUserById2(UserAndContext uac, Context context, Connection con) { + private CachedUser loadUserById2(UserAndContext uac, Context context, boolean populateLoginCache, Connection con) { try { User user = delegate.getUser(getEffectiveContext(uac.getContextId(), context), uac.getUserId(), con); - String loginInfo = user.getLoginInfo(); + String loginInfo = populateLoginCache ? user.getLoginInfo() : null; if (loginInfo != null) { logins2UserCache.put(new ContextIdAndString(uac.getContextId(), loginInfo), I(user.getId())); }