Skip to content

Commit

Permalink
Merge pull request #1498 from /issues/1468-perf-delete-unique-values
Browse files Browse the repository at this point in the history
Fix #1468: Improve performance of deleting values in table pa_unique_values (backport)
  • Loading branch information
banterCZ authored Apr 30, 2024
2 parents ecb4f98 + 9245e8a commit f5a8b93
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@
package io.getlime.security.powerauth.app.server.database.repository;

import io.getlime.security.powerauth.app.server.database.model.entity.UniqueValueEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
* Repository for accessing stored tokens for token-based authentication.
* Repository for accessing unique values related to cryptography.
*
* @author Petr Dvorak, petr@wultra.com
* @author Roman Strobl, roman.strobl@wultra.com
*/
@Repository
public interface UniqueValueRepository extends CrudRepository<UniqueValueEntity, String> {

int deleteAllByTimestampExpiresBefore(Date timestampExpires);
@Modifying
@Query("DELETE FROM UniqueValueEntity u WHERE u.timestampExpires < :timestampExpires")
int deleteExpiredValues(Date timestampExpires);

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean persistUniqueValue(final UniqueValueType type, final String uniqu
* Remove expired unique values in the database.
*/
public void deleteExpiredUniqueValues() {
int expiredCount = uniqueValueRepository.deleteAllByTimestampExpiresBefore(Date.from(Instant.now()));
int expiredCount = uniqueValueRepository.deleteExpiredValues(Date.from(Instant.now()));
logger.debug("Removed {} expired unique values", expiredCount);
}
}

0 comments on commit f5a8b93

Please sign in to comment.