im trying to have news feed like facebook.
Database Dump http://www.2shared.com/document/RXQ13S-n/exported.html
i have feed table, which gets feed for text, image or video. i want to group the latest video and images feed and show them as one row and if someone feed comes after it, then group gets break for that row. the following query is working perfectly fine for that, but its really slow, because im trying to retrive the owner rows and the people he is following (his friends) to. i been trying to fix this query for over week now and im just clueless now on what to do with it and how to fix it.
would really appreciate your help, if you guys know any ideas for this.
i can change the table structure, if it will make the query run faster. if you guys have any other table structure like facebook news feed. i would be honor to use it.
slow query
SELECT SQL_CALC_FOUND_ROWS feed.user_id, username, feed_id, reply_id, thread_id, app_id,
TYPE , text, vote_score, spam, GROUP_CONCAT( COALESCE( feed_id, 0 ) ) AS feed_ids, GROUP_CONCAT( COALESCE( media_id, 0 ) ) AS media_ids, GROUP_CONCAT( COALESCE( thumbnail, 0 ) ) AS thumbnails, GROUP_CONCAT( COALESCE( direct_link, 0 ) ) AS direct_links, group_position, count( * ) AS group_total, feed.created_date
FROM (
SELECT @group := @group + ( NOT (COALESCE( @type ,TYPE ) = TYPE )
OR TYPE = 'feed'
OR NOT (COALESCE( @user_id , user_id ) = user_id)) AS group_position,
@type := TYPE , @user_id := user_id, m . *
FROM (
SELECT @group :=0, @type := NULL , @user_id :=0
)vars, feed m
ORDER BY created_date DESC
)feed
LEFT JOIN
user
ON feed.user_id =
user.user_id
LEFT JOIN
follow
ON user.user_id =
following_user_id
WHERE
(feed.user_id = 'ijvVJhOrPqF')
OR (follower_user_id = 'ijyVJhQrPqF')
GROUP BY group_position