S
S
sema-fedotov2020-01-25 13:39:27
MySQL
sema-fedotov, 2020-01-25 13:39:27

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

5 answer(s)
D
DevMan, 2020-01-25
@sema-fedotov

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.

A
Alexey Kovalev, 2020-01-25
@vio

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.

V
v1rtuoz, 2020-01-26
@v1rtuoz

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.

D
Dmitry Makarov, 2020-01-27
@MDiMaI666

Even easier - count the elapsed seconds from the entry date

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question