Skip to content

refactor(word): optimize indexes and transaction boundaries#335

Merged
SolfE merged 13 commits into
developfrom
codex/word-index-transaction-optimization
Jun 22, 2026
Merged

refactor(word): optimize indexes and transaction boundaries#335
SolfE merged 13 commits into
developfrom
codex/word-index-transaction-optimization

Conversation

@SolfE

@SolfE SolfE commented Jun 22, 2026

Copy link
Copy Markdown
Member

Summary

word 도메인의 인덱스와 트랜잭션 경계를 재정리하고, 단어 변형 조회/북마크 흐름의 부수 효과를 줄였습니다.

Problem

  • WordService 내부 저장 메서드에 @Transactional이 붙어 있었지만 self-invocation 구조라 실제 트랜잭션 경계가 불명확했습니다.
  • 북마크 서비스의 트랜잭션이 단어 생성/저장 흐름까지 감싸면서 word persistence 작업이 의도보다 넓은 트랜잭션에 참여할 수 있었습니다.
  • 북마크 삭제 경로에서 WordVariantService가 variant가 없으면 AI 호출 후 새 variant를 저장할 수 있어, 삭제 API에 생성 side effect가 있었습니다.
  • word/variant 인덱스와 repository 메서드 중 현재 조회 패턴과 맞지 않거나 사용되지 않는 항목이 남아 있었습니다.

Solution

  • WordPersistenceService를 분리해 Word, WordVariant, InvalidWord 저장 책임과 트랜잭션 경계를 별도 Bean으로 이동했습니다.
  • BookmarkService의 불필요한 트랜잭션을 제거해 북마크 작업이 word persistence 트랜잭션을 감싸지 않도록 했습니다.
  • WordVariantService를 조회 전용으로 축소해 북마크 삭제 경로에서 AI 호출/저장이 발생하지 않도록 했습니다.
  • 단어 조회 패턴에 맞춰 word compound index를 정리하고, 사용하지 않는 repository 메서드를 제거했습니다.
  • AI 분석 실패를 invalid word로 캐시하지 않고 도메인 실패로 전파하도록 정리했습니다.

Changes

  • WordPersistenceService 추가: 분석 결과 저장, 강제 재분석 저장, invalid word 저장 책임 분리
  • WordService: 저장 로직 제거, AI 호출/조회/single-flight 흐름 조율 중심으로 축소
  • WordVariantService: getOriginalForms() 조회 전용화, getOrCreateWordVariants() 제거
  • BookmarkService: bookmark write 메서드의 @Transactional 제거
  • Word, WordVariant: compound index 정리 및 중복/불필요 인덱스 제거
  • WordRepository, WordVariantRepository, 기타 repository: 미사용 메서드 제거
  • WordAiService, WordsException: AI 분석 실패 도메인 에러 전파 보강
  • 관련 단위 테스트 수정/추가

Example

  • 단어 생성 요청은 AI 분석 후 WordPersistenceService에서 Word + WordVariant + InvalidWord 저장 구간만 처리합니다.
  • 북마크 삭제 요청은 기존 WordVariant 매핑만 조회하고, 매핑이 없더라도 AI 호출이나 새 variant 저장을 수행하지 않습니다.
  • homograph처럼 하나의 입력 단어가 여러 원형 후보를 가질 수 있는 경우 응답은 여러 결과를 유지하고, 북마크는 기존 정책대로 첫 번째 원형을 사용합니다.

검증:

  • ./gradlew compileJava
  • ./gradlew test --tests com.linglevel.api.word.service.WordServiceTest --tests com.linglevel.api.word.service.WordVariantServiceTest --tests com.linglevel.api.word.service.WordSingleFlightRedisCoordinatorTest

Related Issues

없음

@SolfE SolfE changed the title [codex] optimize word indexes and transaction boundaries refactor(word): optimize indexes and transaction boundaries Jun 22, 2026
@SolfE SolfE marked this pull request as ready for review June 22, 2026 07:39

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68af7086df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/java/com/linglevel/api/bookmark/service/BookmarkService.java Outdated
@SolfE

SolfE commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 199655505f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@SolfE

SolfE commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 36bc123dd8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@SolfE SolfE merged commit 5095385 into develop Jun 22, 2026
1 check passed
@SolfE SolfE deleted the codex/word-index-transaction-optimization branch June 22, 2026 08:13
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.

1 participant