Skip to content

Commit

Permalink
Merge pull request #154 from softeerbootcamp4th/fix/153-when-draw-tar…
Browse files Browse the repository at this point in the history
…get-0

[fix] 이벤트 유저 수가 0명일 때 set 기반 추첨을 진행하면 예외가 발생하는 문제 수정(#153)
  • Loading branch information
blaxsior authored Aug 23, 2024
2 parents 7c49003 + 8287bd2 commit b63c4c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public class AccSumBasedWinnerPicker implements WinnerPicker {
@Override
public List<PickTarget> pick(List<PickTarget> items, long count) {
long maxPickCount = Math.min(items.size(), count);
// TODO: 둘 중 하나를 선택하는 최적 조건 분석하기.
if (count - maxPickCount <= 10 || // 두 값 차이가 작을 때
// pick count = 0이면 아무 것도 안하게 수정
if(maxPickCount == 0) return Collections.emptyList();
if (count - maxPickCount <= 10 ||// 두 값 차이가 작을 때
((double) count / maxPickCount) <= 1.1 ) {
return pickMany(items, maxPickCount);
} else {
Expand Down Expand Up @@ -50,6 +51,7 @@ protected List<PickTarget> pickManyUsingSet(List<PickTarget> targets, long count
// 가중합 배열
RandomItem[] items = getAccumulatedItems(targets);
List<PickTarget> pickedTargets = new ArrayList<>();
if(items.length == 0) return pickedTargets;
long bound = items[items.length - 1].score;
// 이미 선택된 대상이 존재하는 공간
Set<Integer> pickedIdxSet = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ public class DrawEventDrawMachine {
@Async
@Transactional
public CompletableFuture<Void> draw(DrawEvent drawEvent) {
try{
Thread.sleep(1000 * 5 * 1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

long drawEventRawId = drawEvent.getId();
// 점수 계산. 추후 추첨 과정과 분리될 수도 있음.
List<DrawEventScorePolicy> policies = drawEvent.getPolicyList();
Expand Down

0 comments on commit b63c4c8

Please sign in to comment.