Skip to content

Commit

Permalink
Repository review #523
Browse files Browse the repository at this point in the history
  • Loading branch information
straumat committed Mar 15, 2024
1 parent 497b8b2 commit 787641f
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public interface AssetGroupRepository extends JpaRepository<AssetGroup, Long> {

/**
* Find an asset group but its asset group id.
* Find an asset group by its asset group id.
*
* @param assetGroupId asset group id
* @return asset group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
public interface AssetRepository extends JpaRepository<Asset, Long> {

/**
* Find an asset by its assetId.
* Find an asset by its asset id.
*
* @param assetId asset od
* @param assetId asset id
* @return asset
*/
Optional<Asset> findByAssetId(String assetId);

/**
* find by asset id.
* Find an asset by its asset id alias.
*
* @param assetIdAlias asset id alias
* @return asset
Expand All @@ -36,7 +36,7 @@ public interface AssetRepository extends JpaRepository<Asset, Long> {
* Takes advantage of PostgreSQL "pg_trgm" and "ILIKE".
*
* @param searchTerm search term
* @param pageable pagination
* @param pageable pagination parameters
* @return results
*/
@Query(value = "SELECT * FROM ASSET WHERE NAME ILIKE %?1%",
Expand All @@ -46,6 +46,7 @@ public interface AssetRepository extends JpaRepository<Asset, Long> {

/**
* Find assets by its complete or partial name.
* Used if the database in use is not PostgreSQL.
*
* @param name complete or partial name
* @param pageable page parameters
Expand All @@ -54,20 +55,20 @@ public interface AssetRepository extends JpaRepository<Asset, Long> {
Page<Asset> findByNameContainsIgnoreCaseOrderByName(String name, Pageable pageable);

/**
* Find assets by asset group id.
* Find assets by its asset group id.
*
* @param assetGroupId asset group id
* @param pageable page parameters
* @param pageable pagination parameters
* @return assets
*/
@SuppressWarnings("checkstyle:MethodName")
Page<Asset> findByAssetGroup_AssetGroupIdOrderById(String assetGroupId, Pageable pageable);

/**
* Find assets by creator id.
* Find assets by its creator username.
*
* @param username username
* @param pageable page parameters
* @param username creator username
* @param pageable pagination parameters
* @return user assets
*/
@SuppressWarnings("checkstyle:MethodName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface AssetStateRepository extends JpaRepository<AssetState, Long> {
* Find all the asset states for a given asset.
*
* @param assetId asset id
* @param pageable page parameters
* @param pageable pagination parameters
* @return asset states
*/
@SuppressWarnings("checkstyle:MethodName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
public interface BitcoinTransactionOutputRepository extends JpaRepository<BitcoinTransactionOutput, Long> {

/**
* Find transaction outputs for the corresponding txid.
* Find all transaction outputs for a bitcoin transaction id.
*
* @param txId transaction id
* @param txId bitcoin transaction id
* @return Bitcoin transaction outputs
*/
List<BitcoinTransactionOutput> findByTxId(String txId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
public interface ProofRepository extends JpaRepository<Proof, Long> {

/**
* Find a proof by its proofId.
* Find a proof by its proof id.
*
* @param proofId proof id
* @return proof
*/
Optional<Proof> findByProofId(String proofId);

/**
* Returns all the proof of an asset.
* Returns all proofs of an asset.
*
* @param assetId asset id
* @param pageable page parameters
* @param pageable pagination parameters
* @return proofs
*/
Page<Proof> findByAssetAssetIdOrderByCreatedOn(String assetId, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ public interface RequestRepository extends JpaRepository<Request, Long> {
Optional<Request> findByRequestId(String requestId);

/**
* Find all requests with the corresponding status.
* Count all requests with the corresponding status.
*
* @param status status
* @return Requests with the corresponding status
* @return number of requests with the corresponding status
*/
List<Request> findByStatusOrderById(RequestStatus status);
long countByStatusOrderById(RequestStatus status);

/**
* Find all requests with the corresponding status.
*
* @param status status
* @param pageable page parameters
* @param pageable pagination parameters
* @return Requests with the corresponding status
*/
List<Request> findByStatusOrderById(RequestStatus status, Pageable pageable);
Expand All @@ -45,7 +45,7 @@ public interface RequestRepository extends JpaRepository<Request, Long> {
* Find all requests with the corresponding status (ordered by id and with pagination).
*
* @param status status filter
* @param pageable page parameters
* @param pageable pagination parameters
* @return Requests with the corresponding status
*/
Page<Request> findByStatusInOrderById(List<RequestStatus> status, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface UniverseServerRepository extends JpaRepository<UniverseServer,
* Find a server by its server address.
*
* @param serverAddress server address
* @return server address
* @return server
*/
Optional<UniverseServer> findByServerAddress(String serverAddress);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
public interface UserLnurlAuthKeyRepository extends JpaRepository<UserLnurlAuthKey, Long> {

/**
* Find a user lnurl-auth by the linking key.
* Find a user lnurl-auth by a linking key.
*
* @param linkingKey linking key
* @return user lnurl-auth key
*/
Optional<UserLnurlAuthKey> findByLinkingKey(String linkingKey);

/**
* Find a user lnurl-auth by the k1.
* Find a user lnurl-auth by a k1.
*
* @param k1 k1
* @return user lnurl-auth key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void purge() {
// =============================================================================================================
// Purge failed requests.
logger.info("Checking if failed request should be purged");
final long allFailedRequestsCount = requestRepository.findByStatusOrderById(FAILURE).size();
final long allFailedRequestsCount = requestRepository.countByStatusOrderById(FAILURE);

if (allFailedRequestsCount > MAXIMUM_FAILED_REQUESTS_STORE) {
logger.info("{} failed requests need to be purged", allFailedRequestsCount - MAXIMUM_FAILED_REQUESTS_STORE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.royllo.explorer.core.repository.universe.UniverseServerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Pageable;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;

Expand Down Expand Up @@ -144,7 +145,7 @@ public void universeBan() {
* @return an add proof request.
*/
private List<AddProofRequest> findAddProofRequestByProof(final String proof) {
return requestRepository.findByStatusOrderById(OPENED)
return requestRepository.findByStatusOrderById(OPENED, Pageable.ofSize(50_000))
.stream()
.filter(request -> request instanceof AddProofRequest)
.map(request -> (AddProofRequest) request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void batch() {
// The rule is that all failed requests besides MAXIMUM_FAILED_REQUESTS_STORE (10 000) must be deleted.
int totalRequests = requestRepository.findAll().size();
assertEquals(60_000, totalRequests);
int failedRequests = requestRepository.findByStatusOrderById(FAILURE).size();
long failedRequests = requestRepository.countByStatusOrderById(FAILURE);
assertEquals(20_000, failedRequests);
assertTrue(requestRepository.findByRequestId("ID_40001").isPresent());
assertTrue(requestRepository.findByRequestId("ID_60000").isPresent());
Expand All @@ -155,7 +155,7 @@ public void batch() {

totalRequests = requestRepository.findAll().size();
assertEquals(50_000, totalRequests);
failedRequests = requestRepository.findByStatusOrderById(FAILURE).size();
failedRequests = requestRepository.countByStatusOrderById(FAILURE);
assertEquals(10_000, failedRequests);
assertTrue(requestRepository.findByRequestId("ID_20001").isPresent());
assertTrue(requestRepository.findByRequestId("ID_30000").isPresent());
Expand Down

0 comments on commit 787641f

Please sign in to comment.