kumaab commented on code in PR #545: URL: https://github.com/apache/ranger/pull/545#discussion_r2006414884
########## security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java: ########## @@ -6741,33 +6741,53 @@ public void run() { getOrCreateLabel(); } + private boolean doesPolicyExist(XXPolicy xPolicy) { + return daoMgr.getXXPolicy().getById(xPolicy.getId()) != null; + } + private void getOrCreateLabel() { LOG.debug("==> AssociatePolicyLabel.getOrCreateLabel(policyId={}, label={})", xPolicy.getId(), policyLabel); - XXPolicyLabel xxPolicyLabel = daoMgr.getXXPolicyLabels().findByName(policyLabel); - - if (xxPolicyLabel == null) { - xxPolicyLabel = daoMgr.getXXPolicyLabels().findByName(policyLabel); + if (doesPolicyExist(xPolicy)) { + LOG.debug("Searching for policyLabel: {}", policyLabel); + XXPolicyLabel xxPolicyLabel = daoMgr.getXXPolicyLabels().findByName(policyLabel); + LOG.debug("Search returned: {}", xxPolicyLabel); if (xxPolicyLabel == null) { - xxPolicyLabel = new XXPolicyLabel(); + LOG.debug("Searching again for policyLabel: {}", policyLabel); + xxPolicyLabel = daoMgr.getXXPolicyLabels().findByName(policyLabel); Review Comment: @mneethiraj do you think searching again is redundant here and can be avoided ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@ranger.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org