Qbox-project / qbx_core

http://qbox-project.github.io
Other
44 stars 107 forks source link

refactor(server/players.lua): Explicitly select columns in SQL queries #490

Closed TransitNode closed 2 weeks ago

TransitNode commented 2 weeks ago

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:

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