This is a refactor of the SQL queries in the server/players.lua file to explicitly select only the necessary columns, improving query performance and database efficiency.
Previously, the fetchBan function used a query like this:
SELECT * FROM bans WHERE ...
This query selects all columns (*) from the bans table, regardless of whether they are actually needed by the function.
However, the fetchBan function only returns two properties in the result object:
return result and {
expire = result.expire,
reason = result.reason,
}
It only uses the expire and reason columns from the query result.
To optimize the query and select only the necessary columns, we can update the fetchBan function to use a query like this:
SELECT expire, reason FROM bans WHERE ...
Now, the query explicitly selects only the expire and reason columns, which are the ones actually used by the function. The same reasoning was applied to the functions: fetchAllPlayerEntities & fetchPlayerEntity, where the latter function would also retrieve data from the inventory & phone_number columns despite not being used by the functions.
Checklist
[ ] I have personally loaded this code into an updated Qbox project and checked all of its functionality.
[x] My pull request fits the contribution guidelines & code conventions.
Description
This is a refactor of the SQL queries in the
server/players.lua
file to explicitly select only the necessary columns, improving query performance and database efficiency.Previously, the fetchBan function used a query like this:
This query selects all columns (*) from the bans table, regardless of whether they are actually needed by the function. However, the fetchBan function only returns two properties in the result object:
It only uses the expire and reason columns from the query result. To optimize the query and select only the necessary columns, we can update the fetchBan function to use a query like this:
Now, the query explicitly selects only the expire and reason columns, which are the ones actually used by the function. The same reasoning was applied to the functions: fetchAllPlayerEntities & fetchPlayerEntity, where the latter function would also retrieve data from the inventory & phone_number columns despite not being used by the functions.
Checklist