Skip to content

Commit

Permalink
chore: refactor crud methods (#38158)
Browse files Browse the repository at this point in the history
## Description
As part of transaction support in PG, we are moving from using the jpa
methods for database operations. This PR is refactoring the code to use
custom repository class for DatasourceStorageRepository from the default
CrudRepository.

## Automation

/ok-to-test tags="@tag.ImportExport"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12406578294>
> Commit: c7efa63
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12406578294&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.ImportExport`
> Spec:
> <hr>Thu, 19 Dec 2024 05:27:22 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Introduced new methods for retrieving and counting `NewAction`
entities based on application ID and IDs collection.

- **Bug Fixes**
- Removed outdated methods from the `NewActionRepositoryCE` interface to
streamline functionality.

- **Refactor**
- Enhanced repository capabilities for managing `NewAction` entities
while maintaining backward compatibility.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
AnaghHegde authored Dec 19, 2024
1 parent 68264f1 commit d9b1729
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ Flux<NewAction> findAllPublishedActionsByContextIdAndContextType(
String contextId, CreatorContextType contextType, AclPermission permission, boolean includeJs);

Flux<NewAction> findAllByApplicationIds(List<String> branchedArtifactIds, List<String> includedFields);

// @Meta(cursorBatchSize = 10000)
// TODO Implement cursor with batch size
Flux<NewAction> findByApplicationId(String applicationId);

// @Meta(cursorBatchSize = 10000)
// TODO Implement cursor with batch size
Flux<NewAction> findAllByIdIn(Iterable<String> ids);

Mono<Long> countByDeletedAtNull();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.StreamSupport;

import static org.springframework.data.mongodb.core.aggregation.Aggregation.group;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.match;
Expand Down Expand Up @@ -488,4 +489,24 @@ public Flux<NewAction> findAllByApplicationIds(List<String> applicationIds, List
.fields(includedFields)
.all();
}

@Override
public Flux<NewAction> findByApplicationId(String applicationId) {
return queryBuilder()
.criteria(Bridge.equal(NewAction.Fields.applicationId, applicationId))
.all();
}

@Override
public Flux<NewAction> findAllByIdIn(Iterable<String> ids) {
List<String> idList = StreamSupport.stream(ids.spliterator(), false).toList();
return queryBuilder().criteria(Bridge.in(NewAction.Fields.id, idList)).all();
}

@Override
public Mono<Long> countByDeletedAtNull() {
return queryBuilder()
.criteria(Bridge.exists(NewAction.Fields.deletedAt))
.count();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@
import com.appsmith.server.projections.IdPoliciesOnly;
import com.appsmith.server.repositories.BaseRepository;
import com.appsmith.server.repositories.CustomNewActionRepository;
import org.springframework.data.mongodb.repository.Meta;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

public interface NewActionRepositoryCE extends BaseRepository<NewAction, String>, CustomNewActionRepository {

@Meta(cursorBatchSize = 10000)
Flux<NewAction> findByApplicationId(String applicationId);

@Meta(cursorBatchSize = 10000)
Flux<NewAction> findAllByIdIn(Iterable<String> ids);

Mono<Long> countByDeletedAtNull();

Flux<IdPoliciesOnly> findIdsAndPolicyMapByApplicationIdIn(List<String> applicationIds);

Flux<IdAndDatasourceIdNewActionView> findIdAndDatasourceIdByApplicationIdIn(List<String> applicationIds);
Expand Down

0 comments on commit d9b1729

Please sign in to comment.