AR-Development / PersistentEmpires-OpenSourced

GNU Affero General Public License v3.0
4 stars 19 forks source link

Optimization - Minor - CreatedAt SQL INSERT #4

Open Heavybob opened 5 months ago

Heavybob commented 5 months ago

This is just a minor observation.

https://github.com/AR-Development/PersistentEmpires-OpenSourced/blob/c1e4c936de5f153c5a137f94610b773239b01bb9/PersistentEmpiresServer/PersistentEmpiresSave/Database/Repositories/DBLogRepository.cs#L26

When using INSERT it appears we're also inserting a value for the CreatedAt for logs. This isn't really a big deal but it might be beneficial to instead remove this value from the insert and just alter the tables column to have the CreatedAt value.

This would mean the server doesn't need to spend those extra precious micro seconds of time per request to get the time and instead pass that to the mysql / mariadb server.

Snah79 commented 5 months ago

Yes that is good habit to use Now(). I do it in my submode like this: var insertsql = $"INSERT INTO logs (CreatedAt, IssuerPlayerId, IssuerPlayerName, ActionType, IssuerCoordinates, LogMessage, AffectedPlayers) " + $"VALUES(Now(), ......

There is just 1 if. Make sure your db and server runs on same machine or at least at same timezone, otherwise it can become a problem. If you cant guarantee that, then its better to pass servers Now to sql.....

Heavybob commented 5 months ago

Absolutely, there would be sync issues if the servers time didn't match the database server however ideally with the persistent empires setup you'd want to have as much low latency as possible between the database and the server otherwise you could introduce the possibility of desync and maybe worse case duplication of items. So a local setup of the database is ideal in the first place.

mentalrob commented 5 months ago

Nice2have

ianespana commented 4 months ago

Make sure your db and server runs on same machine or at least at same timezone [...]. If you cant guarantee that, then its better to pass servers Now to sql

For future reference, this is mostly a non-concern if you design your database correctly. All you have to do is store the data as a timestamp in UTC format