Skip to content

feat: weave에 one-to-many관계도 동작하도록 추가 (제안 및 질문)#23

Draft
9w wants to merge 2 commits intomainfrom
feat/one-to-many
Draft

feat: weave에 one-to-many관계도 동작하도록 추가 (제안 및 질문)#23
9w wants to merge 2 commits intomainfrom
feat/one-to-many

Conversation

@9w
Copy link
Copy Markdown
Contributor

@9w 9w commented Aug 4, 2022

PR 의 종류는 어떤 것인가요?

  • 새로운 기능

무엇을 어떻게 변경했나요?

weaver에 relation을 one-to-many로 설정할 경우 관계되는 모든 데이터를 리턴하도록 수정했습니다

코드 변경을 이해하기 위한 배경지식이 필요하다면 설명 해주세요.

fastdao를 쓰다가 relation을 쓰고싶은데 1:n이 지원이 안돼서 못썼던 케이스가 종종 있었던것이 생각나 수정해 보았습니다
Q. 첫번째 데이터만 리턴하는것이 성능상 문제로인해 의도된것인지 궁금합니다 👀

어떻게 테스트 하셨나요?

스모크 테스트

코드의 실행결과를 볼 수 있는 로그나 이미지가 있다면 첨부해주세요.

 PASS  src/weaver.spec.ts
  weaver
    weave
      ✓ should weave (58 ms)
      ✓ should weave one-to-many relationships (33 ms)
      ✓ should weave nothing (19 ms)
      ✓ should throw (25 ms)

@9w 9w requested review from a team, iolo and soomtong August 4, 2022 01:27
@9w 9w self-assigned this Aug 4, 2022
@github-actions github-actions bot added the enhancement New feature or request label Aug 4, 2022
Copy link
Copy Markdown
Contributor

@soomtong soomtong left a comment

Choose a reason for hiding this comment

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

weaver 에 1:N 을 추가하는 것과 다른 DAO 에 대해 select 한 번 더 하는거랑 어떤 차이가 있을까요?
캐시에 담기는게 목적인 걸까요?

@9w
Copy link
Copy Markdown
Contributor Author

9w commented Aug 4, 2022

넵 어드민 리스팅하는 단계에서도 관계되는 데이터 모두가 필요한 케이스가 있는데
이럴때 relation으로 사용이 가능하다면 캐시가 적용이 되니 성능상 이점이 있지 않을까 생각했습니다.

다른DAO에 직접 select해서 연결하는기능도 개발을 해야되겠지만 relation을 쓸 수 있다면 개발 초기 단계에서 개발도 빨리빨리 진행이 될 수 있을거라 생각해보았습니다 (기본적으로 어드민 CRUD 작업이 초반에 진행이 되기 때문에..)

@soomtong
Copy link
Copy Markdown
Contributor

soomtong commented Aug 4, 2022

예전에 동수님이 이 기능 넣다가 만 기억이 있는데 (오래 되서 가물가물하네요) ...
만약 추가 해야 한다면
내부에서는 기본 동작은 ONE_TO_ONE 타입으로 정의되어 동작하고,
비교를 null, not null 이 아니라, 명시적으로 원투원, 원투매니로 하고
weaving 되는 레코드 사이즈를 제한하는 것도 필요할 것 같아요.

@iolo
Copy link
Copy Markdown
Contributor

iolo commented Aug 17, 2022

1-to-many를 하게되면 고려해야할게 많습니다.

  • N+1 fetch 문제
  • nested/cyclic 문제
  • 영택님이 언급하신 many의 범위에 대한 문제(offset, limit 그리고 sort)
  • 속성 이름을 복수형으로 만드는 문제
    여기에 대한 명쾌한 해결책이 있으면... 그게 바로 ORM이죠 :)

fastdao가 완벽한 orm을 추구하는 것은 아니니...
한계만 명확히 하고... 그 한계를 인지한 상태에서 사용하면 될 듯.
ex. limit는 최대 100개(설정 가능)이고, offset, sort는 무시한다. nested/cyclic은 처리하지 않는다.

@9w 9w marked this pull request as draft March 20, 2024 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants