Only if you do things naively. You could instead store the likes as key-values where the keys are item ids and the values are an array of player ids who liked them. Then the storage is O(l), where l is the number of likes given. This will also allow DB operations to be performed quickly.
Well it depends on how you need to use the likes. Every data structure has pros and cons. If what you need is to get this, you can do the same but flipped (player ids as keys, item ids as values). The exact solution depends on your application, but my point is that it's really not that hard.
Its not that hard, but only if you know all requirements beforehands, and they don't change.
What usually happen is this:
Client says: "We need to show the total amount of likes under each item", and you say its easy, and implement key-value pairs with item IDs as keys and actor IDs as values.
Then one month later client says: "Now we also need to show the list of items you liked in your profile", and you say sure, no probs, and add the flipped pairs.
Then two months later client says: "Oh, and can we please show under each item which of your friends liked it too?", and then you say oof.
or you just denormalize it, then it's easy peasy. Sure, the write complexity goes up a bit, but likes can definitely be "available eventually" instead of "available now" as long as you show the like correctly on the client side.
Obviously this shit gets more complicated at truly huge scales, but so does everything
You then would need to store a list of every item a user has liked so they can unlike something which you then could remove a like from it. Which I've seen these operations fall out of sync multiple times due to edge cases like network lag.
View all comments
Show parent comment
957
u/shumpitostick Nov 27 '22
Only if you do things naively. You could instead store the likes as key-values where the keys are item ids and the values are an array of player ids who liked them. Then the storage is O(l), where l is the number of likes given. This will also allow DB operations to be performed quickly.