Skip to content

Conversation

@iamjooon2
Copy link
Member

@iamjooon2 iamjooon2 commented Jan 30, 2025

태그 검색 API, 전체 태그 조회 구현해놨습니다

Tag Entity 추가

Tag Entity가 추가됐어요 엔티티는 요기

생성 API

태그 검색
[GET] /tags?search=param

전체 조회
[GET] /tags

응답 형식은 두 API 모두 동일합니당

// /tags
// /tags?search=param
{
  "count": 3,
  "tags": [
    {
      "id": 1,
      "name": "go"
    },
    {
      "id": 2,
      "name": "java"
    },
    {
      "id": 3,
      "name": "spring"
    }
  ]
}

고민한 점

  • 디코에서 보셨겠지만 gin index 태우기위해 살짝 삽질을 했는데요, 결론부터 말씀드리자면
client.Tag.Query().
        Where(tag.NameContainsFold(searchParam)).
        All(c)

sqlx같은 다른 라이브러리를 사용하지 않고,
entgo로 ilike %param%; 쿼리를 생성하도록 만들어놨습니다(ilike : 대소문자 구분 안함)

로컬에서 row를 추가/삭제하면서 테스트해본 결과 대략 100개 넘어갈 때부터 trgm 인덱스를 타더라구요
저희 배포시 태그가 100개는 넘어갈 것 같아서 이대로 올립니다~

image

그 외 특이사항

  • 인덱스를 entgo단에서 생성하고 싶었으나, was에서 사용하는 db user 권한이 부족해 코드레벨에서 설정이 먹지 않는 것 가아요
    => migration script에 인덱스 생성하도록 따로 작성해뒀는데, 혹시 문제가 되려나요?!
  • entgo단에서 생성되는 쿼리 로깅 추가해뒀습니다
// entgo/database/database.go
client = client.Debug()

그 외

https://www.postgresql.org/docs/current/pgtrgm.html
https://www.postgresql.org/docs/current/gin.html

@github-actions
Copy link

report: Run #55

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
2 2 0 0 0 0 0 476ms

🎉 All tests passed!

Github Test Reporter

@iamjooon2 iamjooon2 requested a review from pilyang January 30, 2025 08:35
Copy link
Member

@pilyang pilyang left a comment

Choose a reason for hiding this comment

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

굿굿 좋아용

  1. 100개정도 이상일때 인덱스 타는것
    => 매우 좋아용

  2. db migration 생성 관련
    => migration을 자동으로 생성하고나서 이후에 수동으로 생성된 마이그래이션 파일을 수정하면 해당 파일의 해시가 변경되어서 바뀐 해시를 적용시켜줘야해용

실행해줘야할 명령어

atlas migrate hash --dir "file://ent/migrate/migrations"

그런데,, 이렇게 해서 적용해보니까 그 gin index설정하는부분에서 먼가 문제가 생기고있는것같은데,, 이건 나도 한번 추가적으로 확인해봐야할것같네.. (아직 더 찾아보거나 시도를 못해봐서 일단 리뷰로 남겨두기만 합니다)
일단 아래는 실행시켜본것들이야

❯ ./script/create_migration.sh teset
You have a checksum error in your migration directory.

        L3: 20250129135532_20250129_create_tag.sql.sql was edited

Please check your migration files and run 'atlas migrate hash' to re-hash the contents

Error: checksum mismatch
❯ atlas migrate hash --dir "file://ent/migrate/migrations"
❯ ./script/create_migration.sh teset
Error: create index "tag_name" to table: "tags": pq: access method "gin" does not support unique indexes
  1. 그외 코드적인것들 리뷰 남겼습니다

@github-actions
Copy link

report: Run #56

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
2 2 0 0 0 0 0 510ms

🎉 All tests passed!

Github Test Reporter

@github-actions
Copy link

github-actions bot commented Feb 2, 2025

report: Run #57

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
2 2 0 0 0 0 0 536ms

🎉 All tests passed!

Github Test Reporter

Copy link
Member

@pilyang pilyang left a comment

Choose a reason for hiding this comment

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

LGTM

@iamjooon2 iamjooon2 merged commit 934e5f3 into main Feb 8, 2025
2 checks passed
@iamjooon2 iamjooon2 deleted the feat/entity-tag branch February 8, 2025 08:16
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.

3 participants