Like button in my codeigniter website |
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) { |
Messages In This Thread |
Like button in my codeigniter website - by sebastianvirlan - 08-19-2015, 03:20 PM
RE: Like button in my codeigniter website - by mwhitney - 08-20-2015, 08:25 AM
RE: Like button in my codeigniter website - by sebastianvirlan - 08-20-2015, 03:34 PM
RE: Like button in my codeigniter website - by mwhitney - 08-24-2015, 07:58 AM
|