CMD:factions(playerid, params []) { new id, tmp[270], string[1155]; sscanf(params, "u", id); if(pInfo[playerid][pAdmin] < 6) { if (isnull(params)) { format(tmp, sizeof(tmp), "Faction\tLocation\tLeader\n"); strcat(string, tmp); format(tmp, sizeof(tmp), "Police Department\tLos Santos\t%s\n", GetFactionLeader(1)); strcat(string, tmp); format(tmp, sizeof(tmp), "Federal Bureau of Investigations\tLos Santos\t%s\n", GetFactionLeader(2)); strcat(string, tmp); format(tmp, sizeof(tmp), "National Guard\tLas Venturas\t%s\n", GetFactionLeader(3)); strcat(string, tmp); format(tmp, sizeof(tmp), "Paramedics Department\tLos Santos\t%s\n", GetFactionLeader(4)); strcat(string, tmp); format(tmp, sizeof(tmp), "Taxi LS\tLos Santos\t%s\n", GetFactionLeader(5)); strcat(string, tmp); format(tmp, sizeof(tmp), "News Reporter\tLas Venturas\t%s\n", GetFactionLeader(6)); strcat(string, tmp); format(tmp, sizeof(tmp), "School Instructor\tLos Santos\t%s\n", GetFactionLeader(7)); strcat(string, tmp); format(tmp, sizeof(tmp), "Hitman\tLos Santos\t%s\n", GetFactionLeader(8)); strcat(string, tmp); format(tmp, sizeof(tmp), "Grove Street\tLos Santos\t%s\n", GetFactionLeader(9)); strcat(string, tmp); format(tmp, sizeof(tmp), "The Ballas\tLos Santos\t%s\n", GetFactionLeader(10)); strcat(string, tmp); format(tmp, sizeof(tmp), "agos\tLos Santos\t%s\n", GetFactionLeader(11)); strcat(string, tmp); format(tmp, sizeof(tmp), "Russian Mafia\tLas Venturas\t%s\n", GetFactionLeader(12)); strcat(string, tmp); } } return 1; }
GetFactionLeader(id) { new query[200]; mysql_format(MySQLCon, query, sizeof (query), "SELECT user, ID, LastLogin FROM `players` WHERE `Leader` = '%i'", id); new name[MAX_PLAYER_NAME+15], idp, Cache:result = mysql_query(MySQLCon, query); if(cache_num_rows()) { cache_get_field_content(0, "user", name); idp = cache_get_field_content_int(0, "ID"); cache_get_field_content(0, "LastLogin", sLeaderF), strmid(pInfo[idp][pLastLogin], sLeaderF, 0, 255, 255); if(IsPlayerConnected(ReturnUser(name))) { format(name, sizeof (name), "%s (Online)", name); } else { format(name, sizeof (name), "%s (Offline)", name); } } else { format(name, sizeof (name), "No Leader"); sLeaderF = "-"; } cache_delete(result); return name; }
EXPLAIN SELECT user, ID, LastLogin FROM `players` WHERE `Leader` = '1'
Hmm, your datamodel is questionable at best. 'Leader' should be an attribute of Faction, not an attribute of Player. As a quick patch you can put an index on that 'leader' column to speed up table lookups, but in the long term you should probably restructure the datamodel.
Also run an explain query (within phpMyAdmin or other client) and put the output here: PHP код:
|
within phpMyAdmin or other client |
I clearly said, and let me quote and emphasize myself:
This query is only meant for performance analysis. It is not meant to be put in code, nor did I hint that it should be. |
Like I predicted, full table scan and no key. Put an index on the leader column. Go to structure tab and click 'index' button next to leader column. Then run the explain query again.
|