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,76 +709,102 @@ 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)
|
{
|
||||||
{
|
PrintToChat(client, "No zones active on this map");
|
||||||
PrintToChat(client, "No zones active on this map");
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (!autismstate)
|
||||||
if (!autismstate)
|
{
|
||||||
{
|
CheckStagesOnMap(client, 0);
|
||||||
CheckStagesOnMap(client, 0);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
mysql_select_lowest_ordered(client, index, 0, null, 0);
|
||||||
//we have index now from menu selection
|
|
||||||
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];
|
||||||
{
|
data.ReadString(sQuery, sizeof(sQuery));
|
||||||
char sQuery[g_dLength];
|
if (!db || strlen(error))
|
||||||
data.ReadString(sQuery, sizeof(sQuery));
|
{
|
||||||
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;
|
||||||
return;
|
delete results;
|
||||||
}
|
return;
|
||||||
delete data;
|
}
|
||||||
int iclient;
|
int index = data.ReadCell();
|
||||||
if ((iclient = GetClientFromSerial(client_serial)) == 0)
|
Menu menu = data.ReadCell();
|
||||||
return;
|
int l_iPosition = data.ReadCell();
|
||||||
int l_iPosition;
|
int length_increase = data.ReadCell();
|
||||||
char sTime[g_dLength];
|
length_increase++;
|
||||||
//Player Name
|
delete data;
|
||||||
char[] g_cPlayerName = new char[MAX_NAME_LENGTH];
|
int iclient;
|
||||||
char g_cContent[g_dLength];
|
if ((iclient = GetClientFromSerial(client_serial)) == 0)
|
||||||
Menu menu = new Menu(MenuHandler1);
|
return;
|
||||||
|
char sTime[g_dLength];
|
||||||
|
//Player Name
|
||||||
|
char[] g_cPlayerName = new char[MAX_NAME_LENGTH];
|
||||||
|
char g_cContent[g_dLength];
|
||||||
|
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() && l_iPosition < 10)
|
||||||
{
|
{
|
||||||
while (results.RowCount > 0 && results.FetchRow())
|
l_iPosition++;
|
||||||
{
|
results.FetchString(0, g_cPlayerName, MAX_NAME_LENGTH);
|
||||||
l_iPosition++;
|
results.FetchString(1, sTime, sizeof(sTime));
|
||||||
results.FetchString(0, g_cPlayerName, MAX_NAME_LENGTH);
|
Format(g_cContent, sizeof(g_cContent), "#%i: Time: %s - %s", l_iPosition, sTime, g_cPlayerName);
|
||||||
results.FetchString(1, sTime, sizeof(sTime));
|
menu.AddItem("-1", g_cContent, ITEMDRAW_DISABLED);
|
||||||
Format(g_cContent, sizeof(g_cContent), "#%i: Time: %s - %s", l_iPosition, sTime, g_cPlayerName);
|
|
||||||
menu.AddItem("-1", g_cContent, ITEMDRAW_DISABLED);
|
|
||||||
}
|
|
||||||
if (!l_iPosition)
|
|
||||||
{
|
|
||||||
menu.AddItem("-1", "No results. Commands: !toptime !stages", ITEMDRAW_DISABLED);
|
|
||||||
}
|
|
||||||
menu.ExitButton = true;
|
|
||||||
menu.Display(iclient, 0);
|
|
||||||
}
|
}
|
||||||
|
delete results;
|
||||||
|
if (!l_iPosition)
|
||||||
|
{
|
||||||
|
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.Display(iclient, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
|
Loading…
Reference in New Issue
Block a user