Skip to content

Added pagination to application list endpoint #1302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private Mono<Void> autoGrantPermissionsByFolderDefault(String applicationId, @Nu

@Override
public Flux<ApplicationInfoView> getRecycledApplications(String name) {
return userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(null, ApplicationStatus.RECYCLED, false, name);
return userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(null, ApplicationStatus.RECYCLED, false, name, 0, 0);
}

private Mono<Void> checkCurrentUserApplicationPermission(String applicationId, ResourceAction action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ public Mono<ResponseView<UserHomepageView>> getUserHomePage(@RequestParam(requir
public Mono<ResponseView<List<ApplicationInfoView>>> getApplications(@RequestParam(required = false) Integer applicationType,
@RequestParam(required = false) ApplicationStatus applicationStatus,
@RequestParam(defaultValue = "true") boolean withContainerSize,
@RequestParam(required = false) String name) {
@RequestParam(required = false) String name,
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
ApplicationType applicationTypeEnum = applicationType == null ? null : ApplicationType.fromValue(applicationType);
return userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationTypeEnum, applicationStatus, withContainerSize, name)
return userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationTypeEnum, applicationStatus, withContainerSize, name, pageNum, pageSize)
.collectList()
.map(ResponseView::success);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ public Mono<ResponseView<Boolean>> updateEditState(@PathVariable String applicat
public Mono<ResponseView<List<ApplicationInfoView>>> getApplications(@RequestParam(required = false) Integer applicationType,
@RequestParam(required = false) ApplicationStatus applicationStatus,
@RequestParam(defaultValue = "true") boolean withContainerSize,
@RequestParam(required = false) String name);
@RequestParam(required = false) String name,
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize);

@Operation(
tags = TAG_APPLICATION_MANAGEMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface FolderApiService {

Mono<Void> upsertLastViewTime(@Nullable String folderId);

Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType applicationType, @Nullable String name);
Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType applicationType, @Nullable String name, Integer pageNum, Integer pageSize);

Mono<Void> grantPermission(String folderId, Set<String> userIds, Set<String> groupIds, ResourceRole role);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public Mono<Void> upsertLastViewTime(@Nullable String folderId) {
* @return flux of {@link ApplicationInfoView} or {@link FolderInfoView}
*/
@Override
public Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType applicationType, @Nullable String name) {
return buildApplicationInfoViewTree(applicationType, name)
public Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType applicationType, @Nullable String name, Integer pageNum, Integer pageSize) {
var retMono = buildApplicationInfoViewTree(applicationType, name)
.flatMap(tree -> {
FolderNode<ApplicationInfoView, FolderInfoView> folderNode = tree.get(folderId);
if (folderNode == null) {
Expand Down Expand Up @@ -264,7 +264,9 @@ public Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType
});
})
.flatMapIterable(tuple -> tuple.getT1().getChildren())
.map(node -> {
.skip(pageNum * pageSize);
if(pageSize > 0) retMono = retMono.take(pageSize);
return retMono.map(node -> {
if (node instanceof ElementNode<ApplicationInfoView, FolderInfoView> elementNode) {
return elementNode.getSelf();
}
Expand All @@ -284,7 +286,7 @@ private Mono<Tree<ApplicationInfoView, FolderInfoView>> buildApplicationInfoView
.cache();

Flux<ApplicationInfoView> applicationInfoViewFlux =
userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationType, ApplicationStatus.NORMAL, false, null)
userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationType, ApplicationStatus.NORMAL, false, null, 0, 0)
.cache();

Mono<Map<String, String>> application2FolderMapMono = applicationInfoViewFlux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ public Mono<ResponseView<FolderInfoView>> update(@RequestBody Folder folder) {
@Override
public Mono<ResponseView<List<?>>> getElements(@RequestParam(value = "id", required = false) String folderId,
@RequestParam(value = "applicationType", required = false) ApplicationType applicationType,
@RequestParam(required = false) String name) {
@RequestParam(required = false) String name,
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
String objectId = gidService.convertFolderIdToObjectId(folderId);
return folderApiService.getElements(objectId, applicationType, name)
return folderApiService.getElements(objectId, applicationType, name, pageNum, pageSize)
.collectList()
.delayUntil(__ -> folderApiService.upsertLastViewTime(objectId))
.map(ResponseView::success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public interface FolderEndpoints
@GetMapping("/elements")
public Mono<ResponseView<List<?>>> getElements(@RequestParam(value = "id", required = false) String folderId,
@RequestParam(value = "applicationType", required = false) ApplicationType applicationType,
@RequestParam(required = false) String name);
@RequestParam(required = false) String name,
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize);

@Operation(
tags = TAG_FOLDER_MANAGEMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface UserHomeApiService {
Mono<UserHomepageView> getUserHomePageView(ApplicationType applicationType);

Flux<ApplicationInfoView> getAllAuthorisedApplications4CurrentOrgMember(@Nullable ApplicationType applicationType,
@Nullable ApplicationStatus applicationStatus, boolean withContainerSize, @Nullable String name);
@Nullable ApplicationStatus applicationStatus, boolean withContainerSize, @Nullable String name, Integer pageNum, Integer pageSize);

Flux<BundleInfoView> getAllAuthorisedBundles4CurrentOrgMember(@Nullable BundleStatus bundleStatus);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Mono<UserHomepageView> getUserHomePageView(ApplicationType applicationTyp
}

return organizationService.getById(currentOrgId)
.zipWith(folderApiService.getElements(null, applicationType, null).collectList())
.zipWith(folderApiService.getElements(null, applicationType, null, 0, 0).collectList())
.map(tuple2 -> {
Organization organization = tuple2.getT1();
List<?> list = tuple2.getT2();
Expand Down Expand Up @@ -189,7 +189,7 @@ public Mono<UserHomepageView> getUserHomePageView(ApplicationType applicationTyp

@Override
public Flux<ApplicationInfoView> getAllAuthorisedApplications4CurrentOrgMember(@Nullable ApplicationType applicationType,
@Nullable ApplicationStatus applicationStatus, boolean withContainerSize, @Nullable String name) {
@Nullable ApplicationStatus applicationStatus, boolean withContainerSize, @Nullable String name, Integer pageNum, Integer pageSize) {

return sessionUserService.getVisitorOrgMemberCache()
.flatMapMany(orgMember -> {
Expand All @@ -207,7 +207,9 @@ public Flux<ApplicationInfoView> getAllAuthorisedApplications4CurrentOrgMember(@
&& (isNull(name) || StringUtils.containsIgnoreCase(application.getName(), name)))
.cache()
.collectList()
.flatMapIterable(Function.identity());
.flatMapIterable(Function.identity())
.skip((long) pageNum * pageSize);
if(pageSize > 0) applicationFlux = applicationFlux.take(pageSize);

// last view time
Mono<Map<String, Instant>> applicationLastViewTimeMapMono = userApplicationInteractionService.findByUserId(visitorId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void updateByGid() {
public void move() {

Mono<? extends List<?>> mono = folderApiService.move("app01", "folder02")
.then(folderApiService.getElements("folder02", null, null).collectList());
.then(folderApiService.getElements("folder02", null, null, 0, 0).collectList());

StepVerifier.create(mono)
.assertNext(list -> {
Expand Down
Loading