Answer the question
In order to leave comments, you need to log in
Node js persistent work, how to implement?
Good afternoon, there is a game like a clicker.
There are certain items that should add currency once per second.
All data is stored in the MySql database.
How can node js implement such that a certain amount of currency is added to each user per second, depending on their items?
Answer the question
In order to leave comments, you need to log in
you can make crutches on the node / other options, or you can use the built-in capabilities of the DBMS (in the muscle, this is the built-in scheduler).
but for most tasks there is no need to update every second.
Oh, it already hurt from one thought to write to the database so often.
Isn't it bad to introduce the concept of a currency "multiplier" depending on items?
The multiplier has changed - saved it and the time of its change; multiplying the multiplier by the time you get the currency.
The player does not need to know about it.
Isn't it easier to count the currency when its value is really needed? We have the current time and the time of the last request, we take the time delta, we consider how much time should have been added during this time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question