Ambiguous number of employees, using an enum? -
Neil. - 21.10.2014
In my script, I can create a company. Members are allowed to apply in said company. There's no limit as to how many can apply. Though now I have a problem on how to show members of the company (incl. those offline players). Here's my airline enumeration if that matters.
pawn Код:
enum companyData
{
//Credentials
ID,
companyname[MAX_COMPANY_NAME],
code[5],
location[MAX_ZONE_NAME],
//Stats
funds,
totalrevenue,
assets,
forsale,
price,
//Others
motto[128],
announcement[128],
foundedon[MAX_TIMESTAMP_LEN],
//Player
Founder_ID,
CEO_ID,
CIO_ID,
CFO_ID,
HeadManager_ID,
//Spawns
Float:office_x,
Float:office_y,
Float:office_z,
Float:spawn_x,
Float:spawn_y,
Float:spawn_z,
//Non SQL
Text3D:textidx,
pickupidx,
mapidx,
transferownershipID,
}
new companyInfo[MAX_COMPANY][companyData];
I'm using
MySQL
When one executes the command: /members, should I make a query right there and then? or should I use an enum? The number of employees is ambiguous and changes so creating an enum (as I have thought) isn't efficient than constantly querying on the players table. How would I go about doing it? Thanks in advance!
Re: Ambiguous number of employees, using an enum? -
AmigaBlizzard - 21.10.2014
If you want unlimited players to apply for your companies, you should use a query every time.
Enums (or arrays inside that enum) are fixed in size and can only be made larger by editing the code, recompile the gamemode and restart your server.
Re: Ambiguous number of employees, using an enum? -
Neil. - 21.10.2014
Quote:
Originally Posted by AmigaBlizzard
If you want unlimited players to apply for your companies, you should use a query every time.
Enums (or arrays inside that enum) are fixed in size and can only be made larger by editing the code, recompile the gamemode and restart your server.
|
Wouldn't that cause a massive lag though when lots of players use the command at the same time and the number of rows are more than 500 at the worst case? but I do get your point. Guess I'll try it your way then, thanks for the input
Re: Ambiguous number of employees, using an enum? -
EnforcerDon - 21.10.2014
deffineately use a querry. It may be slower, but if you think about it, the alternative is to store the entire list in server ram, which is not exactly best practice, and is certainly not dynamic, considering that you would need to recompile/restart server every time the list of players for the company exceeds the size of your array.
A query may have lag once you get over a certain number of rows, but storing the information in RAM is a complete waste of memory, and could end up causing server crashes, if it were not done carefully.
Re: Ambiguous number of employees, using an enum? -
Neil. - 21.10.2014
Quote:
Originally Posted by EnforcerDon
deffineately use a querry. It may be slower, but if you think about it, the alternative is to store the entire list in server ram, which is not exactly best practice, and is certainly not dynamic, considering that you would need to recompile/restart server every time the list of players for the company exceeds the size of your array.
A query may have lag once you get over a certain number of rows, but storing the information in RAM is a complete waste of memory, and could end up causing server crashes, if it were not done carefully.
|
That enlightened it up fairly well. Just a while ago I did that for my Houses (where I would show the player the houses he owned.) instead of looping over 300 houses, I just did a query and it executed around 50ms. I don't know if that would hold up for a thousand of them though.
Re: Ambiguous number of employees, using an enum? -
Anzipane - 21.10.2014
Quote:
Originally Posted by Neil.
That enlightened it up fairly well. Just a while ago I did that for my Houses (where I would show the player the houses he owned.) instead of looping over 300 houses, I just did a query and it executed around 50ms. I don't know if that would hold up for a thousand of them though.
|
50ms is actually A LOT of time for a query to execute! Either your code is really inefficient or your database is not on the same machine as your samp-server..
Re: Ambiguous number of employees, using an enum? -
iZN - 21.10.2014
Quote:
Originally Posted by Neil.
That enlightened it up fairly well. Just a while ago I did that for my Houses (where I would show the player the houses he owned.) instead of looping over 300 houses, I just did a query and it executed around 50ms. I don't know if that would hold up for a thousand of them though.
|
You must be using threaded query along with cache or ORM-system? 50ms is perfect.
Quote:
Originally Posted by Anzipane
50ms is actually A LOT of time for a query to execute! Either your code is really inefficient or your database is not on the same machine as your samp-server..
|
What? MySQL is not like a magic wand which will give you like 5-10ms (If you're expecting that with a huge amount of data being loaded). "ALOT" is meaning like the OP just said 50 minutes lol, come on.
Re: Ambiguous number of employees, using an enum? -
Neil. - 22.10.2014
Quote:
Originally Posted by Anzipane
50ms is actually A LOT of time for a query to execute! Either your code is really inefficient or your database is not on the same machine as your samp-server..
|
The post below you doesn't support that premise.
Quote:
Originally Posted by iZN
You must be using threaded query along with cache or ORM-system? 50ms is perfect.
|
Thanks for confirming my notion
, just wondering though, would that hold up pretty well for a thousand houses?