Yes, that was the question.
I edited my script to use non-threaded queries using mysql_query to load my data now, using the cache.
I thought the loading was slow when it got to my 212 vehicles, but it was slow because mysql_debug was enabled.
Logfile was 275Kb after starting the server once.
pawn Code:
// This function is used to load all speedcameras, gas-stations from MySQL when starting the server (called only during OnFilterscriptInit)
SQL_Data_Load()
{
// Setup local variables
new Query[128], Cache:result;
printf("********************************************************************************");
// Send a query to load all speedcameras from MySQL
format(Query, sizeof(Query), "SELECT * FROM %s", table_speedcams);
result = mysql_query(SQL_db, Query, true);
// Print some debug info to the server console
printf("*** Loading speed-cameras from MySQL using \"%s\"", Query);
CamerasLoad();
cache_delete(result, SQL_db);
printf(" ");
// Send a query to load all gas-stations from MySQL
format(Query, sizeof(Query), "SELECT * FROM %s", table_gasstations);
result = mysql_query(SQL_db, Query, true);
// Print some debug info to the server console
printf("*** Loading gas-stations from MySQL using \"%s\"", Query);
GasStationsLoad();
cache_delete(result, SQL_db);
printf(" ");
// Send a query to load all police-stations from MySQL
format(Query, sizeof(Query), "SELECT * FROM %s", table_policestations);
result = mysql_query(SQL_db, Query, true);
// Print some debug info to the server console
printf("*** Loading police-stations from MySQL using \"%s\"", Query);
PoliceStationsLoad();
cache_delete(result, SQL_db);
printf(" ");
// Send a query to load all vehicle-info from MySQL
format(Query, sizeof(Query), "SELECT * FROM %s", table_vehicleinfo);
result = mysql_query(SQL_db, Query, true);
// Print some debug info to the server console
printf("*** Loading vehicle-info from MySQL using \"%s\"", Query);
VehicleInfoLoad();
cache_delete(result, SQL_db);
printf("********************************************************************************");
return 1;
}
// This function is called to load the speedcameras
CamerasLoad()
{
// Setup local variables
new Rows, CamID, CameraName[50], MaxSpeed, Float:x, Float:y, Float:z, Float:rot, CountSuccess, CountFailed, Query[128];
// Get the amount of rows (cameras)
Rows = cache_get_row_count(SQL_db);
// If there are any rows (cameras) loaded, load data and create them
if (Rows >= 1)
{
// Loop through all rows
for (new Row; Row < Rows; Row++)
{
// Load the data
CamID = cache_get_field_content_int(Row, "ID", SQL_db);
cache_get_field_content(Row, "Name", CameraName, SQL_db, sizeof(CameraName));
MaxSpeed = cache_get_field_content_int(Row, "CamSpeed", SQL_db);
x = cache_get_field_content_float(Row, "X", SQL_db);
y = cache_get_field_content_float(Row, "Y", SQL_db);
z = cache_get_field_content_float(Row, "Z", SQL_db);
rot = cache_get_field_content_float(Row, "Angle", SQL_db);
// Check if the CamID is invalid (out of range)
if ((CamID < 0) || (CamID >= MAX_CAMERAS))
{
// Count the amount of failed cameras (invalid CamID's)
CountFailed++;
printf("*** ERROR: Invalid CamID found in table %s: %i (entry deleted)", table_speedcams, CamID);
mysql_format(SQL_db, Query, sizeof(Query), "DELETE FROM %s WHERE ID = '%i'", table_speedcams, CamID);
mysql_tquery(SQL_db, Query, "", "");
// Continue with the next speedcamera from the MySQL query
continue;
}
// Check if the CamSpeed is invalid (0 or lower)
if (MaxSpeed <= 0)
{
// Count the amount of failed cameras (invalid MaxSpeed)
CountFailed++;
printf("*** ERROR: Invalid CamSpeed found in table %s: CamID %i, MaxSpeed %i (entry deleted)", table_speedcams, CamID, MaxSpeed);
mysql_format(SQL_db, Query, sizeof(Query), "DELETE FROM %s WHERE ID = '%i'", table_speedcams, CamID);
mysql_tquery(SQL_db, Query, "", "");
// Continue with the next speedcamera from the MySQL query
continue;
}
// Create the camera at the given CamID (there should be no duplicate cameras with the same ID as the table-structure doesn't allow it, ID = primary key)
SetupSpeedCamera(x, y, z, rot, MaxSpeed, CameraName, CamID);
// Count the succesfully created cameras
CountSuccess++;
}
}
// Print the amount of speedcams loaded for debugging
printf("*** Speed-cameras loaded: %i (successful: %i, failed: %i)", Rows, CountSuccess, CountFailed);
return 1;
}
// This function is called to load the gas-stations
GasStationsLoad()
{
// Setup local variables
new Rows, GasID, Name[50], Float:x, Float:y, Float:z, CountSuccess, CountFailed, Query[128];
// Get the amount of rows (gas-stations)
Rows = cache_get_row_count(SQL_db);
// If there are any rows (gas-stations) loaded, load data and create them
if (Rows >= 1)
{
// Loop through all rows
for (new Row; Row < Rows; Row++)
{
// Load the data
GasID = cache_get_field_content_int(Row, "ID", SQL_db);
cache_get_field_content(Row, "Name", Name, SQL_db, sizeof(Name));
x = cache_get_field_content_float(Row, "X", SQL_db);
y = cache_get_field_content_float(Row, "Y", SQL_db);
z = cache_get_field_content_float(Row, "Z", SQL_db);
// Check if the GasID is invalid (out of range)
if ((GasID < 0) || (GasID >= MAX_GASSTATIONS))
{
// Count the amount of failed gas-stations (invalid GasID's)
CountFailed++;
printf("*** ERROR: Invalid GasID found in table %s: %i (entry deleted)", table_gasstations, GasID);
mysql_format(SQL_db, Query, sizeof(Query), "DELETE FROM %s WHERE ID = '%i'", table_gasstations, GasID);
mysql_tquery(SQL_db, Query, "", "");
// Continue with the next gas-station from the MySQL query
continue;
}
// Create the gas-station at the given GasID (there should be no duplicate gas-stations with the same ID as the table-structure doesn't allow it, ID = primary key)
SetupGasStation(x, y, z, Name, GasID);
// Count the succesfully created gas-stations
CountSuccess++;
}
}
// Print the amount of gas-stations loaded for debugging
printf("*** Gas-stations loaded: %i (successful: %i, failed: %i)", Rows, CountSuccess, CountFailed);
return 1;
}
// This function is called to load the police-stations
PoliceStationsLoad()
{
// Setup local variables
new Rows, PoliceID, Name[50], Float:x, Float:y, Float:z, CountSuccess, CountFailed, Query[128];
// Get the amount of rows (police-stations)
Rows = cache_get_row_count(SQL_db);
// If there are any rows (police-stations) loaded, load data and create them
if (Rows >= 1)
{
// Loop through all rows
for (new Row; Row < Rows; Row++)
{
// Load the data
PoliceID = cache_get_field_content_int(Row, "ID", SQL_db);
cache_get_field_content(Row, "Name", Name, SQL_db, sizeof(Name));
x = cache_get_field_content_float(Row, "X", SQL_db);
y = cache_get_field_content_float(Row, "Y", SQL_db);
z = cache_get_field_content_float(Row, "Z", SQL_db);
// Check if the PoliceID is invalid (out of range)
if ((PoliceID < 0) || (PoliceID >= MAX_POLICESTATIONS))
{
// Count the amount of failed police-stations (invalid PoliceID's)
CountFailed++;
printf("*** ERROR: Invalid PoliceID found in table %s: %i (entry deleted)", table_policestations, PoliceID);
mysql_format(SQL_db, Query, sizeof(Query), "DELETE FROM %s WHERE ID = '%i'", table_policestations, PoliceID);
mysql_tquery(SQL_db, Query, "", "");
// Continue with the next police-station from the MySQL query
continue;
}
// Create the police-station at the given PoliceID (there should be no duplicate police-stations with the same ID as the table-structure doesn't allow it, ID = primary key)
SetupPoliceStation(x, y, z, Name, PoliceID);
// Count the succesfully created police-stations
CountSuccess++;
}
}
// Print the amount of police-stations loaded for debugging
printf("*** Police-stations loaded: %i (successful: %i, failed: %i)", Rows, CountSuccess, CountFailed);
return 1;
}
// This function is called to load the vehicle-info
VehicleInfoLoad()
{
// Setup local variables
new Rows, ID, Price, Float:MaxFuel, Float:Consump, RefuelT, Disabled, CountSuccess, CountFailed, Query[128], vModel;
// Get the amount of rows (vehicle-info)
Rows = cache_get_row_count(SQL_db);
// If there are any rows (vehicle-info) loaded, load data and overwrite default script-values
if (Rows >= 1)
{
// Loop through all rows
for (new Row; Row < Rows; Row++)
{
// Load the data
ID = cache_get_field_content_int(Row, "ID", SQL_db);
Price = cache_get_field_content_int(Row, "Price", SQL_db);
MaxFuel = cache_get_field_content_float(Row, "MaxFuel", SQL_db);
Consump = cache_get_field_content_float(Row, "Consumption", SQL_db);
RefuelT = cache_get_field_content_int(Row, "RefuelTime", SQL_db);
Disabled = cache_get_field_content_int(Row, "Disabled", SQL_db);
// Check if the ID is invalid (out of range)
if ((ID < 0) || (ID >= sizeof(AVehicleInfo)))
{
// Count the amount of failed vehicle-info entries (invalid ID's)
CountFailed++;
printf("*** ERROR: Invalid ID found in table %s: %i (entry deleted)", table_vehicleinfo, ID);
mysql_format(SQL_db, Query, sizeof(Query), "DELETE FROM %s WHERE ID = '%i'", table_vehicleinfo, ID);
mysql_tquery(SQL_db, Query, "", "");
// Continue with the next vehicle-info entry from the MySQL query
continue;
}
// Store all the data
AVehicleInfo[ID][VehiclePrice] = Price;
AVehicleInfo[ID][VehicleMaxFuel] = MaxFuel;
AVehicleInfo[ID][FuelConsumption] = Consump;
AVehicleInfo[ID][RefuelTime] = RefuelT;
if (Disabled == 1)
AVehicleInfo[ID][VehicleDisabled] = true;
else
AVehicleInfo[ID][VehicleDisabled] = false;
// Count the succesfully loaded vehicle-info entries
CountSuccess++;
}
}
// Print the amount of vehicle-info entries loaded for debugging
printf("*** Vehicle-info loaded: %i (successful: %i, failed: %i)", Rows, CountSuccess, CountFailed);
return 1;
}
This is my data-loading function for now.
This loads 1 speedcam, 23 gas-stations, 7 police-stations and 212 vehicle-models.
And it goes lightning fast, less than a second.
I want to keep this like it is now because now my data is loaded before the server is open to the public.
This is one such instance where it's impossible/unwanted to get mysql_query removed.
The data MUST be loaded in a certain sequence and the data must be present before any player is allowed to connect to avoid bugged players.