DEV Community

[Comment from a deleted post]
Collapse
 
gnsp profile image
Ganesh Prasad • Edited

A real consumer facing implementation would be much more complex than that. Here are a few simple changes to the schema to make the implementation little more efficient:

  1. The like count should be an integer field(column) in each post record (row in the table).

  2. Like table should be indexed on author (assuming author/username is unique). A safer approach is to use an userID as foreign key.

  3. The like relationship between post and user should be cached for better read performance. For each user we can use a set datastructure to cache the post IDs of liked posts.