0
\$\begingroup\$

I am building a Travian clone for learning purposes using FastAPI for the backend. I want to update my current logged user tables whenever they are making a new request (such as loading a new page) unlike updating tables every x seconds.

Since I am using FastAPI, I found that a middleware could be a good option to update tables for every new HTTP request. However, there are a lot of tables that may be updated:

  • Resources (always)
  • Ingoing attacks
  • Outgoing attacks
  • Building / Upgrading buildings
  • Building / Upgrading troops ...
  1. What would be the best approach to update my tables for every new HTTP request? Updating every table may be a bit more time-consuming but probably easier to manage.

  2. This is related to question 1, but since I chose to update my tables on every call, I must store somewhere a timestamp of a column last_updated_timestamp in order to calculate the new value. Should I create this column for every table that is re-calculated or should I hold a single last_updated_timestamp value for every table?

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Does every single http request cause a change to every table, or are there some requests that are more specific? (eg. an "Attack" request might only need to update the attacks tables, not the building/upgrading tables). If you're trying to update your tables to account for stuff going on "in the background" unrelated to the current request, my advice would be: don't. Update that information lazily when it's needed, as shown here and here. \$\endgroup\$
    – DMGregory
    Commented May 14, 2022 at 17:21
  • \$\begingroup\$ Yep, I was trying to update your tables to account for stuff going on "in the background" unrelated to the current request but I will probably follow your suggestion \$\endgroup\$ Commented May 14, 2022 at 17:38
  • \$\begingroup\$ For your second link, it's interesting but where should I store this timestamp, in an isolated table? \$\endgroup\$ Commented May 14, 2022 at 17:41
  • 1
    \$\begingroup\$ That depends on what event the timestamp is recording. If it's the time the attack was initiated, it goes in the corresponding row for that attack in the attack table. If it's the time the build queue was updated, it goes in the corresponding row for that build order in the building table, etc. \$\endgroup\$
    – DMGregory
    Commented May 14, 2022 at 17:49
  • 1
    \$\begingroup\$ If that got you on the right track, consider posting an Answer below describing your solution. \$\endgroup\$
    – DMGregory
    Commented May 14, 2022 at 19:16

0

You must log in to answer this question.

Browse other questions tagged .