Skip to content

Commit

Permalink
Mosip 18523 perf fixes (#665)
Browse files Browse the repository at this point in the history
* Add cacheable to uin hash salt repo

* Minor refactor

* Fix to cache key
  • Loading branch information
loganathan-sekaran authored Nov 23, 2021
1 parent 5903235 commit 571fd64
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 49 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.mosip.authentication.common.service.repository;
import static io.mosip.authentication.core.constant.IdAuthCommonConstants.UIN_HASH_SALT;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -21,6 +23,7 @@ public interface IdaUinHashSaltRepo extends JpaRepository<IdaUinHashSalt, Intege
* @param id the id
* @return String salt
*/
@Cacheable(cacheNames = UIN_HASH_SALT)
@Query("select salt from IdaUinHashSalt where id = :id")
public String retrieveSaltById(@Param("id") Integer id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public boolean verifySignature(String signature, String domain, String requestDa
*/
public String hash(String id) throws IdAuthenticationBusinessException {
int saltModuloConstant = env.getProperty(IdAuthConfigKeyConstants.UIN_SALT_MODULO, Integer.class);
Integer idModulo = (int)(Long.parseLong(id) % saltModuloConstant);
Integer idModulo = getModulo(id, saltModuloConstant);
String hashSaltValue = uinHashSaltRepo.retrieveSaltById(idModulo);
if (hashSaltValue != null) {
try {
Expand All @@ -365,6 +365,10 @@ public String hash(String id) throws IdAuthenticationBusinessException {
}
}

private int getModulo(String id, int saltModuloConstant) {
return (int)(Long.parseLong(id) % saltModuloConstant);
}

/**
* Gets the x 509 certificate.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ public final class IdAuthCommonConstants {
public static final String FAILURE = "failure";

public static final String QUALITY_SCORE = "qualityScore";

public static final String UIN_HASH_SALT = "uin_hash_salt";



private IdAuthCommonConstants() {
Expand Down

0 comments on commit 571fd64

Please sign in to comment.