reduced query time by checking for length of column, not a real long term solution but should be good enough for some years
This commit is contained in:
		
							parent
							
								
									2128687809
								
							
						
					
					
						commit
						a9ce7a6fea
					
				| @ -709,13 +709,32 @@ public Action cmd_timerCheckTop(int client, int args) | |||||||
| 	CheckTop(client, 0, 0); | 	CheckTop(client, 0, 0); | ||||||
| 	return Plugin_Handled; | 	return Plugin_Handled; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | public void mysql_select_lowest_ordered(int client, int index, int length_increase, Menu menu, int l_iPosition) | ||||||
|  | { | ||||||
|  |     int l_iZoneCount = unloze_zoneCount(); | ||||||
|  |     char sQuery[g_dLength]; | ||||||
|  |     if (l_iZoneCount < 2) | ||||||
|  |         Format(sQuery, sizeof(sQuery), "SELECT name, `%s` FROM `zetimer_table` WHERE LENGTH(`%s`) = (select min(LENGTH(`%s`) + %i) from unloze_racetimer_css.zetimer_table zt where `%s` != 0.000) and `%s` != 0.000 order by `%s` ASC LIMIT 10", g_cMapname, g_cMapname, g_cMapname, length_increase, g_cMapname, g_cMapname, g_cMapname); | ||||||
|  |     else | ||||||
|  |         Format(sQuery, sizeof(sQuery), "SELECT name, `%sS%i` FROM `zetimer_table` WHERE LENGTH(`%sS%i`) = (select min(LENGTH(`%sS%i`) + %i) from unloze_racetimer_css.zetimer_table zt where `%sS%i` != 0.000) and `%sS%i` != 0.000 order by `%sS%i` ASC LIMIT 10", g_cMapname, index, g_cMapname, index,  g_cMapname, index, length_increase, g_cMapname, index, g_cMapname, index, g_cMapname, index); | ||||||
|  |     //LogMessage("sQuery: %s", sQuery); | ||||||
|  |     DataPack hDataPack = new DataPack(); | ||||||
|  |     hDataPack.WriteCell(GetClientSerial(client)); | ||||||
|  |     hDataPack.WriteString(sQuery); | ||||||
|  |     hDataPack.WriteCell(index); | ||||||
|  |     hDataPack.WriteCell(menu); | ||||||
|  |     hDataPack.WriteCell(l_iPosition); | ||||||
|  |     hDataPack.WriteCell(length_increase); | ||||||
|  |     g_dDatabase.Query(SQL_Select_Top_Callback, sQuery, hDataPack); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| // Purpose:  | // Purpose:  | ||||||
| //---------------------------------------------------------------------------------------------------- | //---------------------------------------------------------------------------------------------------- | ||||||
| public void CheckTop(int client, int index, int autismstate) | public void CheckTop(int client, int index, int autismstate) | ||||||
| { | { | ||||||
|     int l_iZoneCount = unloze_zoneCount(); |     int l_iZoneCount = unloze_zoneCount(); | ||||||
| 	char sQuery[g_dLength]; |  | ||||||
|     //PrintToChatAll("checktop l_iZoneCount: %i", l_iZoneCount); |     //PrintToChatAll("checktop l_iZoneCount: %i", l_iZoneCount); | ||||||
|     if (l_iZoneCount < 1) |     if (l_iZoneCount < 1) | ||||||
|     { |     { | ||||||
| @ -727,44 +746,44 @@ public void CheckTop(int client, int index, int autismstate) | |||||||
|         CheckStagesOnMap(client, 0); |         CheckStagesOnMap(client, 0); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 	//we have index now from menu selection |     mysql_select_lowest_ordered(client, index, 0, null, 0); | ||||||
| 	if (l_iZoneCount < 2) |  | ||||||
| 		Format(sQuery, sizeof(sQuery), "SELECT name, `%s` FROM `zetimer_table` WHERE `%s` != 0.000 ORDER BY LENGTH(`%s`) ASC, `%s` ASC LIMIT 10", g_cMapname, g_cMapname, g_cMapname, g_cMapname); |  | ||||||
| 	else |  | ||||||
| 		Format(sQuery, sizeof(sQuery), "SELECT name, `%sS%i` FROM `zetimer_table` WHERE `%sS%i` != 0.000 ORDER BY LENGTH(`%sS%i`) ASC, `%sS%i` ASC LIMIT 10", g_cMapname, index, g_cMapname, index,  g_cMapname, index, g_cMapname, index); |  | ||||||
| 	DataPack hDataPack = new DataPack(); |  | ||||||
| 	hDataPack.WriteCell(GetClientSerial(client)); |  | ||||||
| 	hDataPack.WriteString(sQuery); |  | ||||||
| 	g_dDatabase.Query(SQL_Select_Top_Callback, sQuery, hDataPack); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| public void SQL_Select_Top_Callback(Database db, DBResultSet results, const char[] error, DataPack data) | public void SQL_Select_Top_Callback(Database db, DBResultSet results, const char[] error, DataPack data) | ||||||
| { | { | ||||||
|     ResetPack(data); |     ResetPack(data); | ||||||
|     int client_serial = data.ReadCell(); |     int client_serial = data.ReadCell(); | ||||||
| 	if (!db || strlen(error)) |  | ||||||
|         { |  | ||||||
|     char sQuery[g_dLength]; |     char sQuery[g_dLength]; | ||||||
|     data.ReadString(sQuery, sizeof(sQuery)); |     data.ReadString(sQuery, sizeof(sQuery)); | ||||||
|  |     if (!db || strlen(error)) | ||||||
|  |     { | ||||||
|             LogError("Query error 2: %s", error);    |             LogError("Query error 2: %s", error);    | ||||||
|             LogError("actual query: %s", sQuery); |             LogError("actual query: %s", sQuery); | ||||||
|             delete data; |             delete data; | ||||||
|  |             delete results; | ||||||
|             return; |             return; | ||||||
|     } |     } | ||||||
|  |     int index = data.ReadCell(); | ||||||
|  |     Menu menu = data.ReadCell(); | ||||||
|  |     int l_iPosition = data.ReadCell(); | ||||||
|  |     int length_increase = data.ReadCell(); | ||||||
|  |     length_increase++; | ||||||
|     delete data; |     delete data; | ||||||
|     int iclient; |     int iclient; | ||||||
|     if ((iclient = GetClientFromSerial(client_serial)) == 0) |     if ((iclient = GetClientFromSerial(client_serial)) == 0) | ||||||
|         return; |         return; | ||||||
|         int l_iPosition; |  | ||||||
|     char sTime[g_dLength]; |     char sTime[g_dLength]; | ||||||
|     //Player Name |     //Player Name | ||||||
|     char[] g_cPlayerName = new char[MAX_NAME_LENGTH]; |     char[] g_cPlayerName = new char[MAX_NAME_LENGTH]; | ||||||
|     char g_cContent[g_dLength]; |     char g_cContent[g_dLength]; | ||||||
|         Menu menu = new Menu(MenuHandler1); |     if (menu == null) | ||||||
|  |     { | ||||||
|  |         menu = new Menu(MenuHandler1); | ||||||
|         menu.SetTitle("Maptimer: %s", g_cMapname); |         menu.SetTitle("Maptimer: %s", g_cMapname); | ||||||
|  |     } | ||||||
|     if (results != INVALID_HANDLE) |     if (results != INVALID_HANDLE) | ||||||
|     { |     { | ||||||
| 		while (results.RowCount > 0 && results.FetchRow()) |         while (results.RowCount > 0 && results.FetchRow() && l_iPosition < 10) | ||||||
|         { |         { | ||||||
|             l_iPosition++; |             l_iPosition++; | ||||||
|             results.FetchString(0, g_cPlayerName, MAX_NAME_LENGTH); |             results.FetchString(0, g_cPlayerName, MAX_NAME_LENGTH); | ||||||
| @ -772,10 +791,17 @@ public void SQL_Select_Top_Callback(Database db, DBResultSet results, const char | |||||||
|             Format(g_cContent, sizeof(g_cContent), "#%i: Time: %s - %s", l_iPosition, sTime, g_cPlayerName); |             Format(g_cContent, sizeof(g_cContent), "#%i: Time: %s - %s", l_iPosition, sTime, g_cPlayerName); | ||||||
|             menu.AddItem("-1", g_cContent, ITEMDRAW_DISABLED); |             menu.AddItem("-1", g_cContent, ITEMDRAW_DISABLED); | ||||||
|         } |         } | ||||||
|  |         delete results; | ||||||
|         if (!l_iPosition) |         if (!l_iPosition) | ||||||
|         { |         { | ||||||
|             menu.AddItem("-1", "No results. Commands: !toptime !stages", ITEMDRAW_DISABLED); |             menu.AddItem("-1", "No results. Commands: !toptime !stages", ITEMDRAW_DISABLED); | ||||||
|         } |         } | ||||||
|  |         else if (l_iPosition < 10) | ||||||
|  |         { | ||||||
|  |             //did 2 mins googling but found nothing about menus needing to be cleaned | ||||||
|  |             mysql_select_lowest_ordered(iclient, index, length_increase, menu, l_iPosition); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|         menu.ExitButton = true; |         menu.ExitButton = true; | ||||||
|         menu.Display(iclient, 0); |         menu.Display(iclient, 0); | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user