Skip to content

perf: GraphQL 배치 조회 + OpenAI 배치 분석으로 subrequest 절감#15

Merged
soobing merged 2 commits intomainfrom
perf/10-reduce-subrequests
Apr 8, 2026
Merged

perf: GraphQL 배치 조회 + OpenAI 배치 분석으로 subrequest 절감#15
soobing merged 2 commits intomainfrom
perf/10-reduce-subrequests

Conversation

@soobing
Copy link
Copy Markdown
Contributor

@soobing soobing commented Apr 8, 2026

문제

Cloudflare Workers의 50 subrequest 한도를 초과하여 postLearningStatus가 실패함.
PR 제출 파일이 10개 이상이면 한도에 도달 (기존: 18 + 3N 회).

해결

1. fetchCohortUserSolutions GraphQL 배치 조회

  • 유저의 머지된 PR별로 REST API를 개별 호출하던 방식 제거
  • GraphQL 쿼리에 files(first: 100)를 포함시켜 프로젝트 아이템 조회 시 파일 경로도 함께 가져옴
  • ~20회 → ~5회 (per-PR REST 호출 완전 제거)

2. generateBatchApproachAnalysis OpenAI 배치 분석

  • 파일별 개별 OpenAI API 호출을 단일 배치 호출로 통합
  • 단건이면 기존 generateApproachAnalysis로 위임하여 동작 동일
  • N회 → 1회

결과

전체 subrequest: 18+3N → 18+2N

N=5:   33회 → 28회  ✅
N=10:  48회 → 38회  ✅
N=15:  63회 → 48회  ✅

Test plan

  • PR opened 시 학습 현황 댓글이 정상 생성되는지 확인
  • PR synchronize(push) 시 댓글이 업데이트되는지 확인
  • 재참여자의 경우 이번 기수 문제만 카운팅되는지 확인
  • Cloudflare Workers 로그에서 subrequest 한도 에러가 발생하지 않는지 확인

Closes #10

🤖 Generated with Claude Code

Cloudflare Workers의 50 subrequest 한도를 초과하는 문제를 해결한다.

1. fetchCohortUserSolutions: PR별 REST 파일 조회를 제거하고
   GraphQL에 files(first:100)를 포함시켜 한 번에 조회
   (기존 ~20회 → ~5회)

2. postLearningStatus: 파일별 OpenAI 개별 호출을
   generateBatchApproachAnalysis로 일괄 처리
   (기존 N회 → 1회)

전체 subrequest: 18+3N → 18+2N (N=5 기준 33→28회)

Closes #10

Co-Authored-By: sounmind <37020415+sounmind@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 8, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
github 92f8ca1 Commit Preview URL

Branch Preview URL
Apr 08 2026, 01:35 PM

@soobing soobing requested a review from sounmind April 8, 2026 13:26
@soobing soobing self-assigned this Apr 8, 2026
Copy link
Copy Markdown
Member

@sounmind sounmind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

전체적으로 subrequest 절감 방향이 적절합니다. 두 가지만 확인 부탁드려요.

1. 스텝 번호 중복

handlers/learning-status.js에서 스텝 5가 두 번 나옵니다.

// 5. AI 일괄 분석 (1회 OpenAI 호출로 모든 제출 파일 분석)
...
// 5. 카테고리별 진행도 계산

새 단계가 삽입되면서 이후 번호가 밀려야 할 것 같아요.

2. 단건 위임 시 usageundefined

generateBatchApproachAnalysis에서 단건일 때 generateApproachAnalysis로 위임하는데, 기존 함수는 { matches, explanation }만 반환하고 usage 필드가 없습니다.

const result = await generateApproachAnalysis(...);
return {
  results: [{ matches: result.matches, explanation: result.explanation }],
  usage: result.usage,  // → undefined (null이 아님)
};

PR #12의 usage 추적 기능과 합쳐지면 totalUsage != null 체크가 undefinednull과 다르게 처리하므로 의도치 않게 usage 섹션이 렌더링될 수 있어요. result.usage ?? null로 바꾸거나, generateApproachAnalysis에서도 usage를 반환하도록 맞추면 될 것 같습니다.

- learning-status.js: 스텝 5 중복을 5~9로 순번 재정렬
- openai.js: 단건 위임 시 result.usage ?? null로 undefined 방지

Co-Authored-By: sounmind <37020415+sounmind@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sounmind
Copy link
Copy Markdown
Member

sounmind commented Apr 8, 2026

정정: 2번 (usage undefined) 이슈

다시 확인해보니, undefined != null은 JavaScript에서 false를 반환합니다. != 연산자는 nullundefined를 동일하게 취급하기 때문에 hasUsage = totalUsage != null 체크에서 undefined도 정상적으로 걸러집니다.

따라서 실제 버그는 아닙니다. 잘못 짚었습니다, 죄송합니다.

의미상 result.usage ?? null로 명시하면 더 읽기 쉽긴 하지만, 필수 수정 사항은 아닙니다.

@soobing soobing merged commit a430e96 into main Apr 8, 2026
1 check passed
soobing added a commit that referenced this pull request Apr 8, 2026
…sts"

This reverts commit a430e96, reversing
changes made to d51353a.
soobing added a commit that referenced this pull request Apr 8, 2026
revert: PR #15 (GraphQL 배치 조회 + OpenAI 배치 분석) 원복
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

리트코드 스터디 재수하시는 분들 풀이한 문제 카운팅 해결

2 participants