Welcome Guest, Not a member yet? Register   Sign In
Like button in my codeigniter website
#1

I am creating a like button for my website so I need to know what is the best method?

Count vs Increment vs Count + Increment vs Cache

Please choose a scenario:

1. Incrementing a number


Pros

Easier and more performant to lookup a single number.
Easy to modify to skew results.

Cons

People can likely find a way to like multiple times.
Can't count individual likes if they need to be recalculated.
Can't remove likes for stuff like a user was deleted/banned.

2. Storing individual likes


Pros

Can be re-calculated if the numbers get skewed for some reason.
More verbose, you can literally count the likes yourself.
Can store identifying information with the likes to prevent multiple likes for same question or answer.
Can remove a vote if a user is deleted/banned (or just don't count votes from those users).
Cons
Less performant to count many rows, especially if the number gets really, really high (think [m|b|tr]illions+).
Uses more space. Likely not an issue, but when you have tons of rows, it might. Would need quite a lot though.

3. Cache query with $this->db->cache_on();


Pros

Speed and database will thank me

Cons

If people only view the the page would be ok because instead of select data from database would get from cache. Assuming that the like button is pressed every second on my website. So on that insert I must delete the cache from the server to make new one with the new count yes? So every second the cache will be deleted and replaced with new one. Would be this ok? This is my function to create a like.

PHP Code:
function create($data) {
$this->db->cache_delete('stream''question');
$this->db->cache_delete('stream''category');
$this->db->insert($this->_table$data);
return 
$this->db->insert_id();

Reply


Messages In This Thread
Like button in my codeigniter website - by sebastianvirlan - 08-19-2015, 03:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB