Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor/#431] 이메일을 통한 아티클 조회 메인페이지 조회수 API에 포함되도록 쿼리 수정 #432

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

belljun3395
Copy link
Collaborator

🎫 연관 이슈

resolved: #431

💁‍♂️ PR 내용

  • 이메일을 통한 아티클 조회 메인페이지 조회수 API에 포함되도록 쿼리 수정

🙏 작업

  • 기존 조회 쿼리에 이메일에서 오픈한 것을 추가해서 조회하도록 수정하였습니다

🙈 PR 참고 사항

  • 이메일 전송 이벤트에 아직 인덱스를 추가하지 않았는데 관련 논의가 필요할 것 같습니다
  • 해당 PR 구현처럼 조인으로 조회수를 합칠지 아님 이메일 오픈 이벤트도 조회 카운트 테이블에 같이 누적되게 할지 논의가 필요할 것 같습니다

📸 스크린샷

🤖 테스트 체크리스트

  • 체크 미완료
  • 체크 완료

@github-actions github-actions bot added the refactor 기존 기능에 대해 개선할 때 사용됩니다. label Oct 10, 2024
@belljun3395
Copy link
Collaborator Author

belljun3395 commented Oct 10, 2024

오프셋 관련

select row_rank_tb.OFFSET
from (
  select
    tvc.ARTICLE_ID as `ARTICLE_ID`,
    row_number() over (order by
      tvc.VIEW_COUNT desc,
      tvc.ARTICLE_ID desc
    ) as `OFFSET`
  from (
    // 이메일 전송 기록의 오픈 이벤트와 아티클 조회수를 합친다.
    select
      `ARTICLE_VIEW_COUNT`.`ARTICLE_ID`,
      (`ARTICLE_VIEW_COUNT`.`VIEW_COUNT` + ifnull(
        evc.VIEW_COUNT,
        0
      )) as `VIEW_COUNT`
    from `ARTICLE_VIEW_COUNT`
      left outer join (
        select
          `SEND_ARTICLE_EVENT_HISTORY`.`ARTICLE_ID`,
          count(`SEND_ARTICLE_EVENT_HISTORY`.`ARTICLE_ID`) as `VIEW_COUNT`
        from `SEND_ARTICLE_EVENT_HISTORY`
        group by `SEND_ARTICLE_EVENT_HISTORY`.`ARTICLE_ID`
      ) as `evc`
        on `ARTICLE_VIEW_COUNT`.`ARTICLE_ID` = evc.ARTICLE_ID
  ) as `tvc`
) as `row_rank_tb`
where row_rank_tb.ARTICLE_ID = 1

@belljun3395
Copy link
Collaborator Author

오프셋 기준으로 아티클 아이디 조회

select
  article_view_count_offset_tb.ARTICLE_ID as `articleId`,
  article_view_count_offset_tb.VIEW_COUNT as `views`
from (
  // 이메일 전송 기록의 오픈 이벤트와 아티클 조회수를 합친다.
  select
    `ARTICLE_VIEW_COUNT`.`ARTICLE_ID`,
    (`ARTICLE_VIEW_COUNT`.`VIEW_COUNT` + ifnull(
      evc.VIEW_COUNT,
      0
    )) as `VIEW_COUNT`,
    `ARTICLE_VIEW_COUNT`.`CATEGORY_CD`
  from `ARTICLE_VIEW_COUNT`
    left outer join (
      select
        `SEND_ARTICLE_EVENT_HISTORY`.`ARTICLE_ID`,
        count(`SEND_ARTICLE_EVENT_HISTORY`.`ARTICLE_ID`) as `VIEW_COUNT`
      from `SEND_ARTICLE_EVENT_HISTORY`
      group by `SEND_ARTICLE_EVENT_HISTORY`.`ARTICLE_ID`
    ) as `evc`
      on `ARTICLE_VIEW_COUNT`.`ARTICLE_ID` = evc.ARTICLE_ID
  order by
    (evc.VIEW_COUNT) desc,
    `ARTICLE_VIEW_COUNT`.`ARTICLE_ID` desc
  limit 9223372036854775807
  offset 0
) as `article_view_count_offset_tb`
where article_view_count_offset_tb.CATEGORY_CD = 0
limit 11

@belljun3395
Copy link
Collaborator Author

explain-docs.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor 기존 기능에 대해 개선할 때 사용됩니다.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

이메일을 통한 아티클 조회 메인페이지 조회수 API에 포함되도록 수정
1 participant