반응형
알림 추적을 위해 Facebook의 데이터베이스가 어떻게 구성되어 있는지 알아 보려고합니다.
저는 페이스 북처럼 복잡하지 않을 것입니다. 알림을위한 간단한 테이블 구조를 상상한다면 :
알림 (ID, 사용자 ID, 업데이트, 시간);
다음을 사용하여 친구의 알림을받을 수 있습니다.
SELECT `userid`, `update`, `time`
FROM `notifications`
WHERE `userid` IN
(... query for getting friends...)
그러나 읽은 알림과 읽지 않은 알림을 확인하려면 테이블 구조는 무엇입니까?
해결 방법
이것이 최선의 방법인지는 모르겠지만, 다른 사람에게서 아이디어를 얻지 못했기 때문에 이것이 제가 할 일입니다. 이 답변이 다른 사람들에게도 도움이되기를 바랍니다.
우리는 2 개의 테이블이 있습니다
notification
-----------------
id (pk)
userid
notification_type (for complexity like notifications for pictures, videos, apps etc.)
notification
time
notificationsRead
--------------------
id (pk) (i dont think this field is required, anyways)
lasttime_read
userid
아이디어는 알림 테이블에서 알림을 선택하고 notificationRead 테이블에 조인하고 ID> notificationid로 마지막으로 읽은 알림 및 행을 확인하는 것입니다. 알림 페이지가 열릴 때마다 notificationRead 테이블에서 행을 업데이트하십시오.
읽지 않은 알림에 대한 쿼리는 다음과 같습니다 ..
SELECT `userid`, `notification`, `time` from `notifications` `notificationsRead`
WHERE
`notifications`.`userid` IN ( ... query to get a list of friends ...)
AND
(`notifications`.`time` > (
SELECT `notificationsRead`.`lasttime_read` FROM `notificationsRead`
WHERE `notificationsRead`.`userid` = ...$userid...
))
위의 쿼리는 확인되지 않습니다. @espais의 db 디자인 아이디어 덕분에
참조 페이지 https://stackoverflow.com/questions/1887602
반응형
'MySql' 카테고리의 다른 글
MySQL mysql GROUP_CONCAT DISTINCT 여러 열 (0) | 2020.12.22 |
---|---|
MySQL VARCHAR과 CHAR의 차이점은 무엇입니까? (0) | 2020.12.22 |
MySQL for Python 2.7 (0) | 2020.12.22 |
MySQL install MySQL JDBC driver msi (0) | 2020.12.22 |
MySQL 테이블 행 계산 (0) | 2020.12.22 |
댓글