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);
|
||||
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:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void CheckTop(int client, int index, int autismstate)
|
||||
{
|
||||
int l_iZoneCount = unloze_zoneCount();
|
||||
char sQuery[g_dLength];
|
||||
//PrintToChatAll("checktop l_iZoneCount: %i", l_iZoneCount);
|
||||
if (l_iZoneCount < 1)
|
||||
{
|
||||
PrintToChat(client, "No zones active on this map");
|
||||
return;
|
||||
}
|
||||
if (!autismstate)
|
||||
{
|
||||
CheckStagesOnMap(client, 0);
|
||||
return;
|
||||
}
|
||||
//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);
|
||||
int l_iZoneCount = unloze_zoneCount();
|
||||
//PrintToChatAll("checktop l_iZoneCount: %i", l_iZoneCount);
|
||||
if (l_iZoneCount < 1)
|
||||
{
|
||||
PrintToChat(client, "No zones active on this map");
|
||||
return;
|
||||
}
|
||||
if (!autismstate)
|
||||
{
|
||||
CheckStagesOnMap(client, 0);
|
||||
return;
|
||||
}
|
||||
mysql_select_lowest_ordered(client, index, 0, null, 0);
|
||||
}
|
||||
|
||||
public void SQL_Select_Top_Callback(Database db, DBResultSet results, const char[] error, DataPack data)
|
||||
{
|
||||
ResetPack(data);
|
||||
int client_serial = data.ReadCell();
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
char sQuery[g_dLength];
|
||||
data.ReadString(sQuery, sizeof(sQuery));
|
||||
LogError("Query error 2: %s", error);
|
||||
LogError("actual query: %s", sQuery);
|
||||
delete data;
|
||||
return;
|
||||
}
|
||||
delete data;
|
||||
int iclient;
|
||||
if ((iclient = GetClientFromSerial(client_serial)) == 0)
|
||||
return;
|
||||
int l_iPosition;
|
||||
char sTime[g_dLength];
|
||||
//Player Name
|
||||
char[] g_cPlayerName = new char[MAX_NAME_LENGTH];
|
||||
char g_cContent[g_dLength];
|
||||
Menu menu = new Menu(MenuHandler1);
|
||||
ResetPack(data);
|
||||
int client_serial = data.ReadCell();
|
||||
char sQuery[g_dLength];
|
||||
data.ReadString(sQuery, sizeof(sQuery));
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error 2: %s", error);
|
||||
LogError("actual query: %s", sQuery);
|
||||
delete data;
|
||||
delete results;
|
||||
return;
|
||||
}
|
||||
int index = data.ReadCell();
|
||||
Menu menu = data.ReadCell();
|
||||
int l_iPosition = data.ReadCell();
|
||||
int length_increase = data.ReadCell();
|
||||
length_increase++;
|
||||
delete data;
|
||||
int iclient;
|
||||
if ((iclient = GetClientFromSerial(client_serial)) == 0)
|
||||
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);
|
||||
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);
|
||||
results.FetchString(1, sTime, sizeof(sTime));
|
||||
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);
|
||||
l_iPosition++;
|
||||
results.FetchString(0, g_cPlayerName, MAX_NAME_LENGTH);
|
||||
results.FetchString(1, sTime, sizeof(sTime));
|
||||
Format(g_cContent, sizeof(g_cContent), "#%i: Time: %s - %s", l_iPosition, sTime, g_cPlayerName);
|
||||
menu.AddItem("-1", g_cContent, ITEMDRAW_DISABLED);
|
||||
}
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user