Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
API 추가 및 병렬 실행
Browse files Browse the repository at this point in the history
Schedulers.boundedElastic 사용 IO 작업 최적화
  • Loading branch information
ori0o0p committed Feb 14, 2024
1 parent 02c2af8 commit 30c5958
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public Flux<RevisionHistory> getRevisionToPage(@Valid @RequestBody GetRevisionPa
return revisionService.getAllRevisionPaging(request);
}

@GetMapping("/{documentId}")
public Flux<RevisionHistory> getRevisionByDocument(@PathVariable String documentId, @Valid @RequestBody GetRevisionPageRequest request) {
return revisionService.getAllRevisionByDocument(documentId, request);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
import org.bson.types.ObjectId;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Scheduler;

import java.util.List;

@Service
public class RevisionService {
private final RevisionHistoryRepository revisionHistoryRepository;
private final Scheduler scheduler;

public RevisionService(RevisionHistoryRepository revisionHistoryRepository) {
public RevisionService(RevisionHistoryRepository revisionHistoryRepository, Scheduler scheduler) {
this.revisionHistoryRepository = revisionHistoryRepository;
this.scheduler = scheduler;
}

public Flux<RevisionHistory> getUpdatedTop10Revision() {
Expand All @@ -26,17 +29,26 @@ public Flux<RevisionHistory> getUpdatedTop10Revision() {

// 17077 92123
// 17077 44486 최신
public Flux<RevisionHistory> getFilteredRevisions(Flux<RevisionHistory> revisions, String lastRevisionId) {
return revisions.filter(revisionHistory -> lastRevisionId == null || lastRevisionId.isEmpty() ||
new ObjectId(revisionHistory.getId()).getTimestamp() > new ObjectId(lastRevisionId).getTimestamp())
.take(20);
}

public Flux<RevisionHistory> getAllRevisionPaging(GetRevisionPageRequest request) {
String lastRevisionId = request.lastRevisionId();

return revisionHistoryRepository.findAllByOrderByCreatedDateTimeDesc()
.filter(revisionHistory -> lastRevisionId == null || lastRevisionId == "" ||
new ObjectId(revisionHistory.getId()).getTimestamp() > new ObjectId(lastRevisionId).getTimestamp())
.take(10);
return getFilteredRevisions(
revisionHistoryRepository.findAllByOrderByCreatedDateTimeDesc(),
lastRevisionId
).subscribeOn(scheduler);
}

public Flux<RevisionHistory> getAllRevisionByDocument(String documentId) {
return revisionHistoryRepository.findAllByDocumentId(documentId);
public Flux<RevisionHistory> getAllRevisionByDocument(String documentId, GetRevisionPageRequest request) {
String lastRevisionId = request.lastRevisionId();
return getFilteredRevisions(
revisionHistoryRepository.findAllByDocumentId(documentId),
lastRevisionId
).subscribeOn(scheduler);
}

}

0 comments on commit 30c5958

Please sign in to comment.