Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8249537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:34:45+00:00 2026-06-07T23:34:45+00:00

In a project in which I need to implement like/unlike functionality, I want to

  • 0

In a project in which I need to implement like/unlike functionality, I want to know which approach would better than other from performance point of view. If I have to go with insert delete, then what would happen if someone like/unlike it so many times (Then probably most of primary key numbers will be occupied based on like/unlike)?
Does anyone know how social networking sites do it?

EDIT:
My table is as below:

CREATE TABLE `junc_user_share_like` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `jusid` int(10) unsigned NOT NULL,
 `liker` mediumint(8) unsigned NOT NULL,
 `when` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 PRIMARY KEY (`id`),
 UNIQUE KEY `jusid` (`jusid`,`liker`),
 KEY `liker` (`liker`),
 CONSTRAINT `junc_user_share_like_ibfk_1` FOREIGN KEY (`liker`) REFERENCES `user` (`uid`) ON DELETE CASCADE ON UPDATE CASCADE,
 CONSTRAINT `junc_user_share_like_ibfk_2` FOREIGN KEY (`jusid`) REFERENCES `junc_user_share` (`jusid`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB

EDIT 2:
As you said with last updates this is what I’ve inferred:

INSERT INTO likes SET jusid=$jusid, liker=$liker
UPDATE junc_user_share SET likes=likes+1 WHERE id=$id

This works great for likes, but what if someone wants to undo his like? Should I delete record from likes? My problem is exactly here? What to do here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:34:47+00:00Added an answer on June 7, 2026 at 11:34 pm

    Denormalize.

    • have a table with the likes and unlikes (Who did what to which item)
    • have a likes and a unlikes field on the items table, both starting with 0

    On a like/unlike do (assuming 1=like, 0=unlike)

    INSERT INTO likes_unlikes SET item=[id of item], user=[id of user], action=[0|1];
    UPDATE items SET likes=IF([action]=1,likes+1,likes), unlikes=IF([action]=0,unlikes+1,unlikes) WHERE id=[id of item]
    

    A UNIQUE KEY on likes_unlikes(item,user) gives you uniqueness as a present.

    Edit

    After discussion, if you just have likes, but no dislikes, the situation is even easier:

    • only a likes table is needed with item and user id
    • only a likes field is needed on the items table

    the queries are now something like

    INSERT INTO likes SET item=[id of item], user=[id of user];
    UPDATE items SET likes=likes+1 WHERE id=[id of item]
    

    and for reversal of a like:

    DELETE FROM likes WHERE item=[id of item] AND user=[id of user];
    UPDATE items SET likes=likes-1 WHERE id=[id of item]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our project we need to implement Excel-like grid for web, which will look
I'm working on a project in which I need to implement http from scratch;
I'm implementing a interpreter-like project for which I need a strange little scheduling queue.
In a future project I will need to implement functionality meant for searching words
I would like to introduce caching into an existing Spring project which uses JAXB
I would like to know which is the best way to organize the dll
I have a project in which I need to display multiple UITableView instances inside
I have a GWT project in which I need to manually specify currency, number
I am working on a project in which I need to download and parse
I am working on a project in which I need to generate 8 random

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.