For example, most news clients and some communities (more famous as reddit) calculate a weight value according to a certain algorithm, and then sort according to the weight value (refer to:http://www.ruanyifeng.com/blog/2012/03/ranking_algorithm_reddit.html)
Under the scenario of mobile phone app, how should we comprehensively improve the sorting performance?
- If only sorting is carried out in the database, since the fields of order by are generated by algorithms, a large amount of data will inevitably be inefficient. Mysql currently used in products does not support function indexing yet.
- If the data is extracted first and then sorted in the program inside, a large amount of data will occupy a lot of memory in the server, right? It seems that it is not a good way either.
Please have experienced people provide some ideas.
This problem is placed under the node of Android. Do you want to realize weight calculation under Android?
If in the server, agree@zysThe plan, in addition, to reduce the number of calculations, private the following humble opinion:
Add one to the data to be calculatedupdated_atAndcalculated_atFields representing data respectivelyThe latest update time and the last time the weight value was calculated by the sorting algorithm.. When new users vote, update the updated_at field of the data. The calculated_at field of the data is updated after the scheduled task calculates the weight.
Weight Calculation Algorithm inside Pairupdated_atAndcalculated_atFor comparison, whencalculated_at > updated_atAt that time,There is no need to recalculate the weight value repeatedly.
With this simple algorithm, a large part of the data that has not been updated can be effectively removed. In addition, if the old data has been updated, it can also be included in the calculation scope of the weight.