2020-12-17 coding perception

When coding, you still need to think more, and think more about under what circumstances, which logic can be omitted, and which database operations are meaningless. For example, business logic first sets the score of the USER table in the database to 0, and then restarts Calculate the score of each user. At this time, if the score is still 0 for the user, you do not need to participate in the batch update operation, so you can filter out the user data with the score of 0 before doing the batch update operation, so as to avoid unnecessary use. Operation, I hope that friends who see it can be inspired and understand by analogy. Of course, Daniel will definitely not make this kind of mistake, so here is just an example of my not rigorous coding.

In addition, when coding, try to think about the amount of data based on business development as much as possible, and see if there will be problems with the sql search, and will too many objects enter the JVM at a time, leading to frequent GC, causing OOM, and finally Try again if there is a way to change your mind and optimize the code. Here is an example. For example, an e-commerce system has stores in every city. Store data will be added continuously. It can even be considered that there is no upper limit, while the number of cities has an upper limit. You can know by clicking Baidu. How many cities are there, then at this time to fetch data, we must consider whether the number of stores will be too large, and can we try to directly operate the large amount of data at the SQL level according to the table association relationship to avoid a large amount of data being loaded into Heap.

Guess you like

Origin blog.csdn.net/weixin_38106322/article/details/111343522
Recommended