I have a web site written in PHP, where users can upload images, send friends requests, post messages.
The web site is built on CodeIgniter framework.
I want to have a “log” of all of these events. For example, I want to display latest events from all friends. Like facebook, where X liked Y picture or Z posted a new message.
My database structure is something like:
events table:
ID | user_id | event_type | meta_field | date
I have more tables like friendships, images, etc.
The meta_filed and event_type, will specify the data from another table. For example, for a next row in
events table:
1, 4, 3, 12, 2012-12-08
the 3 will specify that the events was a friendship request, and the 12 will be the ID 12 from friendships table, where I have all details about this friendship request.
The question is, is that a good approach of designing the database? How can I sort optimally for example, all latest events of my friends, assuming that I have the friendship table populated with data. Which technologies you suggest me to use for caching or something else that will improve my performance and code quality?
It is very good approach. However, you have to index the field “meta_field” to improve performance when your database is going to be bigger. Indexing that field is easily carried out using phpMyAdmin.