Extremly slow querry
#1

for some reason this query takes 25 seconds to load 21 cars from SQL

PHP код:
stock sql_LoadAllCars() {
    for(new 
0MAX_VEHICLESi++) {
        if(
IsValidVehicle(i)) {
            
DestroyVehicle(i);
            
DestroyDynamic3DTextLabel(vInfo[i][CarText]);
        }
    }
    
mysql_tquery(mysql"SELECT * FROM `cars`""OnVehicleLoad""");
}
public 
OnVehicleLoad() {
    new 
rowsfields;
    
cache_get_data(rowsfieldsmysql);
    if(
rows) {
        for(new 
i=0rowsi++) {
            new 
carid CreateVehicle(cache_get_field_content_int(i,"carid"),cache_get_field_content_float(i,"X"),cache_get_field_content_float(i,"Y"),cache_get_field_content_float(i,"Z"),cache_get_field_content_float(i,"A"),cache_get_field_content_int(i,"color"),cache_get_field_content_int(i,"color2"),0,cache_get_field_content_int(i,"siren"));
            
vInfo[carid][CarID] = cache_get_field_content_int(i,"ID");
            
vInfo[carid][CModel]  = cache_get_field_content_int(i,"carid");
            
vInfo[carid][VCol1] = cache_get_field_content_int(i,"color");
            
vInfo[carid][VCol2] = cache_get_field_content_int(i,"color2");
            
vInfo[carid][VX] =  cache_get_field_content_float(i,"X");
            
vInfo[carid][VY]  = cache_get_field_content_float(i,"Y");
             
vInfo[carid][VZ]  = cache_get_field_content_float(i,"Z");
             
vInfo[carid][VA]  = cache_get_field_content_float(i,"A");
             
vInfo[carid][VSiren] = cache_get_field_content_int(i,"siren");
             
vInfo[carid][VTeam] = cache_get_field_content_int(i,"team");
             
vInfo[carid][VPrice] = cache_get_field_content_int(i,"price");
             
vInfo[carid][ForSale] = cache_get_field_content_int(i,"forsale");
             
vInfo[carid][VOwner] = cache_get_field_content_int(i,"Owner");
             new 
Sname[50],xName[55];
             
cache_get_field_content(i,"OwnerName",Sname);
             
strcpy(xName,Sname,60);
             
vInfo[carid][VHealth] = 1000.00;
             new 
string[64];
            if(
vInfo[carid][ForSale] == 0format(string,sizeof(string),"{FFFFFF}SQL ID: {FF0000}%i\n{FFFFFF}Vehicle Team: {FF0000}%s",vInfo[carid][CarID],TeamInfo[vInfo[carid][VTeam]][TeamName]);
            else if(
vInfo[carid][ForSale] == 1format(string,sizeof(string),"{FF0000}For sale: {FFFFFF}%i$",vInfo[carid][VPrice]);
            
vInfo[carid][CarText] = CreateDynamic3DTextLabel(stringCOLOR_RED,vInfo[carid][VX],vInfo[carid][VY],vInfo[carid][VZ] , 10.0INVALID_PLAYER_IDcarid0, -1, -1, -1100.0);
            if(
vInfo[carid][VOwner] >= 1) {
                
format(string,sizeof(string),"{FF0000}Owner: {FFFFFF}%s",xName);
                
UpdateDynamic3DTextLabelText(vInfo[carid][CarText],COLOR_RED,string);
            }
        }
    }

Any idea why it would be so slow? It also kinda "locks" the server for 25 seconds
Reply
#2

Do you have mysql logging enabled? If so, try disabling it. I also faced the same problem with loading the vehicles before, found out it was caused by the log.
Reply
#3

How do you actually disable it? I removed the debug from the gamemodeinit
PHP код:
mysql_log(LOG_ERROR LOG_WARNING LOG_DEBUG); 
but it still logs stuff
Reply
#4

To be more precise: it slows down the queries when LOG_DEBUG is used. You can have it as:
pawn Код:
mysql_log(LOG_ERROR | LOG_WARNING);
or don't call mysql_log at all since those are by default anyway.

TIP: Don't create variables inside loops, move them outside.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
To be more precise: it slows down the queries when LOG_DEBUG is used. You can have it as:
pawn Код:
mysql_log(LOG_ERROR | LOG_WARNING);
or don't call mysql_log at all since those are by default anyway.

TIP: Don't create variables inside loops, move them outside.
Yep that does the job, It cut down the reload time to 1 second lol.

Thanks a lot guys, and yeah regarding those variables, Ill move them out, just testing this out at the moment so didnt pay too much attention hehe
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)