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 8371009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:03:27+00:00 2026-06-09T14:03:27+00:00

I made a voting system and recorded votes in vote table as a row

  • 0

I made a voting system and recorded votes in vote table as a row like this:

post_id | user_id | votes | date

Then, I add this vote to user-meta table which has a structure like this:

user_id | meta_key | meta_value

In this table, giving an user_id with the meta_key of “votes”, I can save or get an array of post_ids as meta_value.

The reason I save one vote in two tables is–

1. Why use the Vote table?

I need to calculate vote_total and vote_popularity across all posts, this is not easy to do if I save it only as an element of an array in the user’s meta table.

2. Why use the user meta table?

I need to check if a user already voted for a post or not. The user meta is cached once set. So, I only need to do a check of in_array($post_id, $my_voted_posts). If without the user-meta table, for each post the user visit, I will have to check the vote table.

Is there a better way?

Although my voting system works fine. But somehow I feel this is not efficient way of doing this. I would like to consult you professionals, to learn how I can improve it for better performance. Thanks!

  • 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-09T14:03:29+00:00Added an answer on June 9, 2026 at 2:03 pm

    To start, I think checking the vote table is fine if you have an efficient index. You can use composite indexes to index post_id and user_id, which will make a query like select * from votes where post_id = X and vote_id = Y fairly performant.

    There will come a point where you will need to denormalize your data for speed, but I don’t think it should be in the same layer as your normalized data. Perhaps you can use redis / memcache for the user metadata?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a voting on comments like the one this website has(something similar), and
Say I have a voting table, where users can vote on values up, down,
I made a class for DB connection like this: public class DbHelper : IDisposable
Made this nice little loop for hiding and showing div's, works as a charm
i made an .xib file and added my buttons and labels. Then I created
I made a UITableViewCell and I have 20 rows in that table in which
Made a fiddle for this: http://jsfiddle.net/terjeto/MN4FJ/ My problem is that dragleave fires when you
Made a new window application. Right-clicked Frameworks > Add Existing Frameworks. Selected Frameworks folder,
Made a new project, added main.cpp and wrote the code at this URL: http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/example/echo/async_tcp_echo_server.cpp
Is there a ready made solution to allow users to add comments to an

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.