Last active
August 29, 2015 14:05
-
-
Save kcleereman/013f68c088f4ab71e5e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def totalsByItemQ(itemType: String, itemIds: Seq[Int]) = { | |
val dbItemType = itemType.toDBItemType | |
val idList = itemIds.mkString(",") | |
sql""" | |
select subject_id, subject_type, NULL AS user_id, count(id), 'likes' from likes where subject_type=$dbItemType and subject_id in (#$idList) group by subject_id, subject_type | |
union | |
select subject_id, subject_type, NULL AS user_id, count(id), 'follows' from follows where subject_type=$dbItemType and subject_id in (#$idList) group by subject_id, subject_type | |
union | |
select recipient_id, recipient_type, NULL AS user_id, count(id), 'posts' from posts where recipient_type=$dbItemType and recipient_id in (#$idList) group by recipient_id, recipient_type | |
union | |
select recipient_id, recipient_type, NULL AS user_id, count(id), 'comments' from comments where recipient_type=$dbItemType and recipient_id in (#$idList) group by recipient_id, recipient_type | |
union | |
select item_id, item_type, NULL AS user_id, count(id), action_name from activity_logs where item_type = $dbItemType and item_id in (#$idList) and action_name in ('email_share','repost') group by item_id, item_type, action_name | |
union | |
select tagged_id, tagged_type, NULL AS user_id, count(id), 'tags' from tags where tagged_type = $dbItemType and tagged_id in (#$idList) group by tagged_id, tagged_type | |
""".as[SocialActivity] | |
} | |
***** | |
def userTotalsByItemQ(itemType: String, itemIds: Seq[Int], userId: Int) = { | |
val dbItemType = itemType.toDBItemType | |
val idList = itemIds.mkString(",") | |
sql""" | |
select subject_id, subject_type, $userId, count(id), 'likes' from likes where creator_id = $userId and subject_type=$dbItemType and subject_id in (#$idList) group by subject_id, subject_type | |
union | |
select subject_id, subject_type, $userId, count(id), 'follows' from follows where creator_id = $userId and subject_type=$dbItemType and subject_id in (#$idList) group by subject_id, subject_type | |
union | |
select recipient_id, recipient_type, $userId, count(id), 'posts' from posts where creator_id = $userId and recipient_type=$dbItemType and recipient_id in (#$idList) group by recipient_id, recipient_type | |
union | |
select recipient_id, recipient_type, $userId, count(id), 'comments' from comments where creator_id = $userId and recipient_type=$dbItemType and recipient_id in (#$idList) group by recipient_id, recipient_type | |
union | |
select item_id, item_type, $userId, count(id), action_name from activity_logs where user_id = $userId and item_type = $dbItemType and item_id in (#$idList) and action_name in ('email_share','repost') group by item_id, item_type, action_name | |
""".as[SocialActivity] | |
} | |
***** | |
def userTotalsByItemQ(itemType: String, itemIds: Seq[Int], userId: Int) = { | |
val dbItemType = itemType.toDBItemType | |
val idList = itemIds.mkString(",") | |
sql""" | |
select subject_id, subject_type, $userId, count(id), 'likes' from likes where creator_id = $userId and subject_type=$dbItemType and subject_id in (#$idList) group by subject_id, subject_type | |
union | |
select subject_id, subject_type, $userId, count(id), 'follows' from follows where creator_id = $userId and subject_type=$dbItemType and subject_id in (#$idList) group by subject_id, subject_type | |
union | |
select recipient_id, recipient_type, $userId, count(id), 'posts' from posts where creator_id = $userId and recipient_type=$dbItemType and recipient_id in (#$idList) group by recipient_id, recipient_type | |
union | |
select recipient_id, recipient_type, $userId, count(id), 'comments' from comments where creator_id = $userId and recipient_type=$dbItemType and recipient_id in (#$idList) group by recipient_id, recipient_type | |
union | |
select item_id, item_type, $userId, count(id), action_name from activity_logs where user_id = $userId and item_type = $dbItemType and item_id in (#$idList) and action_name in ('email_share','repost') group by item_id, item_type, action_name | |
union | |
select tagged_id, tagged_type, $userId, count(id), 'tags' from tags where creator_id = $userId and tagged_type = $dbItemType and tagged_id in (#$idList) group by tagged_id, tagged_type | |
""".as[SocialActivity] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment