Node.js, the pyramid of doom (even with async), can you write it better?

前端 未结 5 962
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 03:15

I consider myself a very experienced node.js developer.

Yet I still wonder if there is a better way to write the following code so I don\'t get the pyramid of doom..

5条回答
  •  无人共我
    2021-01-15 03:33

    Consider rewriting your code to have less back-and-forth with the database. The rule of thumb I use to estimate an app's performance under heavy load is that every async call will add two seconds to the response (one for the request, and one for the reply).

    For example, is there maybe a way you could offload this logic to the database? Or a way to "SELECT nextval('last_resource_bundle_string_id')" at the same time as you "SELECT * FROM localization_strings WHERE local_id = 10 AND string_key = '" + key[0] + "'" (perhaps a stored procedure)?

提交回复
热议问题