There is a membership table with more and more members, but every time a new member is added, bonuses will be calculated according to certain rules for the previous members. Anyway, with more and more members, the number will increase with each additional member. It’s getting slower and slower (more and more calculations are required), how to deal with this scenario.
You can add members first, and the bonus will be calculated according to a certain time range, such as settling on Monday, building a referral table, recording the related information of the last week, and then running a script to calculate the bonus once a week.
1. Does this settlement occur during the registration step? If so, take out the settlement steps, write them into the table or message queue, and just do the registration process
2. But looking at the comments above about daily settlement, step 1 should be done. Then the entire settlement process should be executed at a fixed time point for all members who joined today (for example, at 1 o'clock in the morning). Slow down. It doesn’t matter, as long as the settlement is completed
Check the table structure to see if it is designed and whether the index can be optimized. And so on
Take out the settlement and run it separately. Write a planned task and run it every day. Or you can write the settlement on the first login of the new user.
For this requirement, you can run the message queue.
The member profit sharing calculation message is first pushed to the message queue, and then a php script is written to receive the message and thrown into the cache, and then it is stored in the database during low business hours every day