Mysql loading slow
#1

Hi guys, i have problem with mysql loading, i have a vps witch are stored all my databases (database for minecraft 1000+ player online everyday...) and i added database for samp.. i have 35 systems loading like this:
Код:
for(new h = 1; h < MAX_ADMINS; h++) {
	    new rows;
		mysql_format(MySQL, Query, sizeof(Query), "SELECT * FROM admini WHERE ID = '%d'", h);
		mysql_query(MySQL,Query);
		rows = cache_get_row_count();
		if(rows > 0) {
			mysql_format(MySQL, Query, sizeof(Query), "SELECT * FROM `admini` WHERE `ID` = '%d'", h);
			mysql_function_query(MySQL, Query, true, "UcitajAdmine", "i", h);
		}
	}
and its just too slow, in this table "admini" i need to wait about 1min to load and table is empty..

Код:
forward UcitajAdmine(id, ConnectionHandle);
public UcitajAdmine(id, ConnectionHandle) {
    new Rows, Fields;
	cache_get_data(Rows, Fields);
	if(Rows > 0) {
	    new tmp[130];
		cache_get_field_content(0, "ime", tmp);
		format(AdminInfo[id][aIme], 129, "%s", tmp);
		
		cache_get_field_content(0, "rank", tmp);
		AdminInfo[id][aRank] = strval(tmp);
	
		cache_get_field_content(0, "neakt", tmp);
		AdminInfo[id][aNeakt] = strval(tmp);
	
		cache_get_field_content(0, "pas", tmp);
		format(AdminInfo[id][aPas], 60, "%s", tmp);
	}
	return 1;
}
but on my localhost its loading instant...
Reply
#2

You're executing dozens of queries in one loop (MAX_ADMINS * 2 queries, to be precise) which is slowing down the MySQL thread. Until all of those queries are finished their execution, no other queries are going to come through as the thread is busy.

The code can be simplified to:

pawn Код:
for(new h = 1; h < MAX_ADMINS; h++)
{
    mysql_format(MySQL, Query, sizeof(Query), "SELECT * FROM admini WHERE ID = %i", h);
    mysql_function_query(MySQL, Query, true, "UcitajAdmine", "i", h);
}
There's no need for an additional "rows" check in there, as that's already done when UcitajAdmine is called.
Reply
#3

It would be even simpler if you had a column that would hold the admin-level for each player.
Normal players have admin-level of 0, while admins have a admin-level higher than 0.

PHP код:
mysql_function_query(MySQL"SELECT * FROM admini WHERE AdminLevel > 0"true"UcitajAdmine"); 
Each row would have all the data about each admin, including their admin-level.
The admin-level can be used to determine which admin has the right to execute certain commands.
/setlevel might only be executed by admins lvl 5 for example, any other admin lower than lvl 5 will not be able to use that command.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)