From f73376335f5e1226d8f08d1c0d7f12b3a2340949 Mon Sep 17 00:00:00 2001 From: thisarawelmilla Date: Tue, 27 Aug 2024 09:17:09 +0530 Subject: [PATCH] Comments addressed. --- .../management/dao/impl/CacheBackedActionMgtDAO.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/dao/impl/CacheBackedActionMgtDAO.java b/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/dao/impl/CacheBackedActionMgtDAO.java index 88bdfeeb0029..df6cdc4a6297 100644 --- a/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/dao/impl/CacheBackedActionMgtDAO.java +++ b/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/dao/impl/CacheBackedActionMgtDAO.java @@ -30,7 +30,6 @@ import org.wso2.carbon.identity.action.management.model.AuthType; import org.wso2.carbon.identity.action.management.model.EndpointConfig; -import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -130,13 +129,11 @@ public Action getActionByActionId(String actionType, String actionId, Integer te ActionTypeCacheKey cacheKey = new ActionTypeCacheKey(actionType); ActionCacheEntry entry = actionCacheByType.getValueFromCache(cacheKey, tenantId); - List actionsFromCache = new ArrayList<>(); /* If the entry for the given action type is not null, get the action list from cache and iterate to get the action by matching action id. */ if (entry != null) { - actionsFromCache = entry.getActions(); - for (Action action: actionsFromCache) { + for (Action action: entry.getActions()) { if (StringUtils.equals(action.getId(), actionId)) { LOG.debug("Action is found from the cache with action Id " + actionId); return action; @@ -150,7 +147,7 @@ public Action getActionByActionId(String actionType, String actionId, Integer te Action action = actionManagementDAO.getActionByActionId(actionType, actionId, tenantId); if (action != null) { - updateCache(action, entry, cacheKey, actionsFromCache, tenantId); + updateCache(action, entry, cacheKey, tenantId); } else { if (LOG.isDebugEnabled()) { LOG.debug("Action with action Id " + actionId + " is not found in cache or DB."); @@ -177,8 +174,7 @@ public Action updateActionEndpoint(String actionType, String actionId, EndpointC tenantId); } - private void updateCache(Action action, ActionCacheEntry entry, ActionTypeCacheKey cacheKey, - List actionsFromCache, int tenantId) { + private void updateCache(Action action, ActionCacheEntry entry, ActionTypeCacheKey cacheKey, int tenantId) { if (LOG.isDebugEnabled()) { LOG.debug("Entry fetched from DB for Action Id " + action.getId() + ". Updating cache."); @@ -186,6 +182,7 @@ private void updateCache(Action action, ActionCacheEntry entry, ActionTypeCacheK /* If the entry for the given action type is not null, add the fetched action to the entry. Then, clear the cache and add the updated entry to the cache. If the entry is null, create a new cache entry.*/ if (entry != null) { + List actionsFromCache = entry.getActions(); actionsFromCache.add(action); actionCacheByType.clearCacheEntry(cacheKey, tenantId); actionCacheByType.addToCache(cacheKey, new ActionCacheEntry(actionsFromCache), tenantId);