D
D
DollyPapper2021-01-06 19:31:51
Python
DollyPapper, 2021-01-06 19:31:51

How to save state between requests for each user?

The database stores a large number of rows.

When you click on the button on the web page, we must take a certain number of records - M, and then randomly select two rows from these M, the next time we click, we must take the next M and choose from them.

The problem is that each time the button is pressed, the request to the server will restart the entire application, and accordingly, each time we will receive the first M rows.

How is it possible to save the position state?
When prompted, it is not an option to start the loop and until it completes, it is not an option to complete the program. The server is not very powerful, and many people will use this service, I would not want to keep several hundred or thousands of python processes running.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2021-01-06
@dimoff66

What does "will restart the entire application" mean? If the page is reloaded every time, the server can sew any information into it, including the required shift. If the page is static and reloading occurs through SPA or AJAX, then the page itself changes the information about the shift.

D
Dr. Bacon, 2021-01-06
@bacon

Well, keep the state in the same database.

The server is not very powerful, and many people will use this service, I would not want to keep several hundred or thousands of python processes running.
it's probably worth starting with the basics, how a web server works, how it interacts with python.

V
Vasily Bannikov, 2021-01-06
@vabka

1. What makes you think that the application is restarted every time?
I ask this question due to the fact that in the case of the same django, the application does not restart.
The shift for each user can be saved somewhere - at least in a dictionary in RAM, at least in a file, at least in the same database where the data is stored.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question