D
D
DeusModus2012-05-05 03:09:14
MySQL
DeusModus, 2012-05-05 03:09:14

Voting for entities (when there are many votes and entities)

There was a question about the optimal way to store voting for some entities. The classic version is an entity counter (something like votes_count) and a separate votes(user_id, vote) table.
However, with this approach, if you leave the opportunity to vote for all entities forever, with a number of, for example, 500,000 pieces that you can vote for and an average number of votes of 3, we get 1,500,000 thousand records in the vote table.
The question is, is there a better way to store this data? And what do you do in situations with highly visited resources and voting for the same comments?

PS: On Habré, it seems impossible to see in the old topic that you voted for the comment, so the table is cleared after the timeout. Apparently to save space and speed up samples.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Sundukov, 2012-05-05
@DeusModus

1,500,000 is not a lot.
There are many options for working with large amounts of data. Depends on what numbers you need to get. For example, if you do not need to remember who specifically voted for what, then you can aggregate the data. Those. take an entity, calculate how many votes were given for period X and record one record in the database, and remove votes from the table with votes for this entity for this period.
If you need everything and always, then we cut the table into pieces and simply save the old records to archive tables. This method does not exclude aggregation at all, it simply remembers all the votes in the system.
PS It is possible. I found my 2nd old voice without any problems.

P
patashnik, 2012-05-05
@patashnik

It is possible, for example, to store not every vote, but some average value of the entity itself.

S
Sergey Sokolov, 2012-05-05
@sergiks

So far, I have acted in the “classical” way described in the question.
But for the nosql architecture, which I am just getting acquainted with on the basis of Amazon SDB, you can collect the id of the users who voted directly in the entity record. Works for a small number of votes for one entity - for an example with harbracomments. For the +\- option, you will have to apparently write id in two fields: who is minus, and who is plus. Or to invent syntax of type id+5or id-3for +5or -3points respectively.
It's good to be aware of the actual use of these points, and the intended scope of use.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question