Talking to myself (MySQL)

Posted by Alert Games on Dec. 22, 2011, 6:16 p.m.

This blog is mainly me figuring out a MYSQL problem. I came up with a solution, but me saying it to myself will help me to see if I did it right. This is for the "Player Feed", which will appear on the index of my website, http://alertgames.net , for registered users when im done.

If you can take anything from this, yay!

What i have:

An option for all members: "Who can see your activity?"

-People who have added you as a friend

-Only people you also have added as a friend

-Nobody can see my activity

What i need:

When showing the feed, address the above.

The feed contains entries of:

-Posting a blog (New blogs are only allowed every 12 hours)

-Getting a highscore in a game (if you have a score, compare)

-Getting achievements in a game (only put a new entry every 24 hours or so)

-Hosting a match

How to going about it:

At first, I was thinking of cross referencing every user of their choice of their privacy option. This would require going through each individual member's choices, then deciding who out of the people that added you should see your posts. In database world, this would mean searching for all people you have added, search all those you found in the user table, and then build an array of people to pull feed entries from, and search the feed table for them.

However, that much work on the server for every time someone visits the home page is a bit much. Instead, I thought of a better way:

How i might do it instead:

Instead of having to pull up the users table, I can store their option in 2 places. Once in the user table, so that it will remember the person's answer if they go into their preferences. The other can be stored in each entry of the friends table. The only downfall of this is that every time you update your option, you have to update each entry of the friends table. But this shouldn't be much of a problem since you will probably not do that often.

Now that the option is stored in the friends table, you have to look at what option they chose. First search all users that you have added on your friends list, and disregard any of them that chose not to have their activity shown. For those who chose the default first option, thats all there is to it.

The problem comes in when you both need to be friends in order to see the post. You don't want to have to make individual queries for each individual person, so I think the best way, would to build up an array of users to check, and before displaying the entries on your feed double check with one query for each of the people with this option. (using a WHERE IN() ). I may play it safe and make the limit like 5 more, incase this happens.

Finally, the feed can be displayed and does all that shinanigans.

Any ideas on another way to do this? Or is it pretty good? Hope this contributed to something lol :D

Comments

JID 13 years ago

cool.

Alert Games 13 years ago

thanks.

JID 13 years ago

you're welcome.

Alert Games 13 years ago

glad that someone read this and commented, so my comments doesnt read (0)

JID 13 years ago

yeah, me too.

pounce4evur 13 years ago

I say it sounds pretty cool. :) I'm glad someone's actually trying to fix this instead of bitching about it and going on with their lives.

Your system sounds very detailed, but overall I really like it. It sounds like you put a lot of thought into it. Thank you. :)

Alert Games 13 years ago

not sure what youre talking about. Yeah its for my site not this one lol. 64digits just needs a filter system, and i dont feel like doing it lol. hence the Driven by Lazyness…

Josea 13 years ago

Why not add an additional attribute to the friends table indicating mutual friendship? This way you can pull all the relevant friends for the feed in only simple query. You only need to maintain this attribute whenever you add or delete a row in the friends table. This lets you get rid of that array of users to check.

Also, you didn't detail how you're pulling the feed from the database, I'd like to see how are you doing it.

pounce4evur 12 years, 12 months ago

I knew that….xP sorry didn't mean to make an ass of myself right there. Still a very nice little system.

Alert Games 12 years, 12 months ago

@Josea: Yeah I was thinking about doing that. That would follow the logic I had for the first problem of their option.

Also, once I code the mysql I'll update the blog with the code that I will use. I'm starting to program it right now, while I wait to go to my relatives for Christmas haha.