수정 알림이 생성되는 경우를 내가 완전히 이해하지 못했거나, 이 문제가 내가 생각했던 것보다 훨씬 광범위한 문제일 수 있다는 것을 방금 깨달았습니다.
주요 가정
사용자 A가 사용자 B가 작성한 내용을 수정하면 다음과 같은 일들이 발생합니다:
post_revisions 테이블에 새로운 행이 추가됩니다.
action_type = 11인 새로운 행이 user_actions 테이블에 추가됩니다.
/u/userB/notifications/edits 경로로 이동하면 사용자 B는 사용자 A가 새로운 수정을 했다는 것을 볼 수 있습니다(이것은 user_actions에 의존합니다).
자신의 게시글의 연필 아이콘을 클릭하면 사용자 B는 사용자 A가 수행한 실제 수정 내용을 볼 수 있습니다(이것은 post_revisions에 의존합니다).
테스트
위 가정들이 정확하다면, 아래 쿼리는 사용자 B(이 경우 id 259)가 생성한 게시글 중 다른 사용자(자기 자신이나 시스템 사용자가 아닌)에 의해 수정된 게시글에 대한 post_revisions 테이블의 모든 행을 action_type = 11인 user_actions의 해당 행과 함께 보여줘야 합니다.
with my_user_posts as (
select
p.id,
p.user_id
from
posts p
where
p.user_id = 259 -- 사용자 id 선택
)
select
up.user_id as my_user_id,
ua.user_id as target_user_id,
pr.post_id,
ua.target_post_id,
pr.user_id as editor_user_id,
ua.acting_user_id,
ua.action_type,
pr.created_at as edit_created_at,
ua.created_at as action_created_at
from
post_revisions pr
inner join my_user_posts up on up.id = pr.post_id
and up.user_id != pr.user_id -- 자기 자신의 수정 제외
and pr.user_id != -1 -- 시스템 수정 제외
left join user_actions ua on ua.target_post_id = pr.post_id
and ua.action_type = 11 -- EDIT 작업만
order by
pr.post_id,
pr.created_at;
예상 출력
모든 행에는 post_revisions 데이터와 user_actions 데이터가 모두 포함되어야 합니다.
실제 출력
일부 post_revisions 행에는 일치하는 user_actions 데이터가 없습니다. 따라서 사용자는 각 게시글의 연필 아이콘을 클릭하여 수정 이력을 볼 수 있지만, 여러 건의 수정을 받았다는 알림을 받지 못했습니다.
(예, 사용자 A가 사용자 B의 게시물을 편집하면 항상 강제 편집 리비전이 생성됩니다. 하지만 이것이 사용자 A가 60초 동안 사용자 B의 게시물을 6번 편집하면 6개의 리비전과 6개의 알림이 생성된다는 뜻은 아닙니다. 위 스크린샷에서 보실 수 있듯이, 리비전과 알림은 각각 하나만 생성됩니다.)
감사합니다, Sam. 그게 제가 기대했던 결과였지만, 제가 발견한 것(적어도 제 사이트에서는)과는 다릅니다. 제 쿼리 결과에서 볼 수 있듯이, 어떤 경우에는 사용자 A가 사용자 B의 게시물을 수정합니다(이 경우 post_revisions 테이블에 행이 추가되지만), user_actions 테이블에는 해당하는 행(action_type 11)이 없습니다. 바로 이 부분이 이해가 되지 않습니다.
with my_user_posts as (
select
p.id,
p.user_id
from
posts p
where
p.user_id = 3 -- 사용자 ID 선택
)
select
up.user_id as my_user_id,
ua.user_id as target_user_id,
pr.post_id,
ua.target_post_id,
pr.user_id as editor_user_id,
ua.acting_user_id,
ua.action_type,
pr.created_at as edit_created_at,
ua.created_at as action_created_at
from
post_revisions pr
inner join my_user_posts up on up.id = pr.post_id
and up.user_id != pr.user_id -- 자기 자신의 수정 제외
and pr.user_id != -1 -- 시스템 수정 제외
left join user_actions ua on ua.target_post_id = pr.post_id
and ua.action_type = 11 -- EDIT 작업만
WHERE
pr.created_at between '2019-08-03' and '2019-08-04'
order by
pr.post_id,
pr.created_at
일부 수치를 계산해 본 결과, 날짜에 따라 자기 자신의 수정이 아닌 post_revisions 중 7%에서 25%까지가 일치하는 user_action이 없는 것으로 나타났습니다.