Revert "Faster /rank, fixes test result"

This reverts commit c2a3444f87.
This commit is contained in:
Dennis Felsing 2024-08-08 18:59:10 +02:00
parent e3dd2895dd
commit 00586a0c4a
2 changed files with 18 additions and 29 deletions

View file

@ -786,25 +786,17 @@ bool CScoreWorker::ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData
// check sort method // check sort method
char aBuf[600]; char aBuf[600];
str_format(aBuf, sizeof(aBuf), str_format(aBuf, sizeof(aBuf),
"SELECT COUNT(DISTINCT Name) + 1 AS Ranking, (SELECT MIN(Time) " "SELECT Ranking, Time, PercentRank "
"FROM ("
" SELECT RANK() OVER w AS Ranking, PERCENT_RANK() OVER w as PercentRank, MIN(Time) AS Time, Name "
" FROM %s_race " " FROM %s_race "
" WHERE Map = ? " " WHERE Map = ? "
" AND Server LIKE ? " " AND Server LIKE ? "
" AND Name = ? "
" GROUP BY Name " " GROUP BY Name "
" LIMIT 1) as minTime " " WINDOW w AS (ORDER BY MIN(Time))"
"FROM %s_race " ") as a "
"WHERE Map = ? " "WHERE Name = ?",
"AND Server LIKE ? " pSqlServer->GetPrefix());
"AND Time < (SELECT MIN(Time) "
" FROM %s_race "
" WHERE Map = ? "
" AND Server LIKE ? "
" AND Name = ? "
" GROUP BY Name "
" LIMIT 1 "
") ",
pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix());
if(pSqlServer->PrepareStatement(aBuf, pError, ErrorSize)) if(pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
{ {
@ -813,11 +805,6 @@ bool CScoreWorker::ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData
pSqlServer->BindString(1, pData->m_aMap); pSqlServer->BindString(1, pData->m_aMap);
pSqlServer->BindString(2, aServerLike); pSqlServer->BindString(2, aServerLike);
pSqlServer->BindString(3, pData->m_aName); pSqlServer->BindString(3, pData->m_aName);
pSqlServer->BindString(4, pData->m_aMap);
pSqlServer->BindString(5, aServerLike);
pSqlServer->BindString(6, pData->m_aMap);
pSqlServer->BindString(7, aServerLike);
pSqlServer->BindString(8, pData->m_aName);
bool End; bool End;
if(pSqlServer->Step(&End, pError, ErrorSize)) if(pSqlServer->Step(&End, pError, ErrorSize))
@ -854,11 +841,13 @@ bool CScoreWorker::ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData
{ {
int Rank = pSqlServer->GetInt(1); int Rank = pSqlServer->GetInt(1);
float Time = pSqlServer->GetFloat(2); float Time = pSqlServer->GetFloat(2);
// CEIL and FLOOR are not supported in SQLite
int BetterThanPercent = std::floor(100.0f - 100.0f * pSqlServer->GetFloat(3));
str_time_float(Time, TIME_HOURS_CENTISECS, aBuf, sizeof(aBuf)); str_time_float(Time, TIME_HOURS_CENTISECS, aBuf, sizeof(aBuf));
if(g_Config.m_SvHideScore) if(g_Config.m_SvHideScore)
{ {
str_format(pResult->m_Data.m_aaMessages[0], sizeof(pResult->m_Data.m_aaMessages[0]), str_format(pResult->m_Data.m_aaMessages[0], sizeof(pResult->m_Data.m_aaMessages[0]),
"Your time: %s", aBuf); "Your time: %s, better than %d%%", aBuf, BetterThanPercent);
} }
else else
{ {
@ -867,14 +856,14 @@ bool CScoreWorker::ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData
if(str_comp_nocase(pData->m_aRequestingPlayer, pData->m_aName) == 0) if(str_comp_nocase(pData->m_aRequestingPlayer, pData->m_aName) == 0)
{ {
str_format(pResult->m_Data.m_aaMessages[0], sizeof(pResult->m_Data.m_aaMessages[0]), str_format(pResult->m_Data.m_aaMessages[0], sizeof(pResult->m_Data.m_aaMessages[0]),
"%s - %s", "%s - %s - better than %d%%",
pData->m_aName, aBuf); pData->m_aName, aBuf, BetterThanPercent);
} }
else else
{ {
str_format(pResult->m_Data.m_aaMessages[0], sizeof(pResult->m_Data.m_aaMessages[0]), str_format(pResult->m_Data.m_aaMessages[0], sizeof(pResult->m_Data.m_aaMessages[0]),
"%s - %s - requested by %s", "%s - %s - better than %d%% - requested by %s",
pData->m_aName, aBuf, pData->m_aRequestingPlayer); pData->m_aName, aBuf, BetterThanPercent, pData->m_aRequestingPlayer);
} }
if(g_Config.m_SvRegionalRankings) if(g_Config.m_SvRegionalRankings)

View file

@ -167,14 +167,14 @@ TEST_P(SingleScore, RankRegional)
{ {
g_Config.m_SvRegionalRankings = true; g_Config.m_SvRegionalRankings = true;
ASSERT_FALSE(CScoreWorker::ShowRank(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError; ASSERT_FALSE(CScoreWorker::ShowRank(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError;
ExpectLines(m_pPlayerResult, {"nameless tee - 01:40.00 - requested by brainless tee", "Global rank 1 - GER rank 1"}, true); ExpectLines(m_pPlayerResult, {"nameless tee - 01:40.00 - better than 100% - requested by brainless tee", "Global rank 1 - GER unranked"}, true);
} }
TEST_P(SingleScore, Rank) TEST_P(SingleScore, Rank)
{ {
g_Config.m_SvRegionalRankings = false; g_Config.m_SvRegionalRankings = false;
ASSERT_FALSE(CScoreWorker::ShowRank(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError; ASSERT_FALSE(CScoreWorker::ShowRank(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError;
ExpectLines(m_pPlayerResult, {"nameless tee - 01:40.00 - requested by brainless tee", "Global rank 1"}, true); ExpectLines(m_pPlayerResult, {"nameless tee - 01:40.00 - better than 100% - requested by brainless tee", "Global rank 1"}, true);
} }
TEST_P(SingleScore, TopServerRegional) TEST_P(SingleScore, TopServerRegional)
@ -205,7 +205,7 @@ TEST_P(SingleScore, RankServerRegional)
g_Config.m_SvRegionalRankings = true; g_Config.m_SvRegionalRankings = true;
str_copy(m_PlayerRequest.m_aServer, "USA", sizeof(m_PlayerRequest.m_aServer)); str_copy(m_PlayerRequest.m_aServer, "USA", sizeof(m_PlayerRequest.m_aServer));
ASSERT_FALSE(CScoreWorker::ShowRank(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError; ASSERT_FALSE(CScoreWorker::ShowRank(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError;
ExpectLines(m_pPlayerResult, {"nameless tee - 01:40.00 - requested by brainless tee", "Global rank 1 - USA rank 1"}, true); ExpectLines(m_pPlayerResult, {"nameless tee - 01:40.00 - better than 100% - requested by brainless tee", "Global rank 1 - USA rank 1"}, true);
} }
TEST_P(SingleScore, RankServer) TEST_P(SingleScore, RankServer)
@ -213,7 +213,7 @@ TEST_P(SingleScore, RankServer)
g_Config.m_SvRegionalRankings = false; g_Config.m_SvRegionalRankings = false;
str_copy(m_PlayerRequest.m_aServer, "USA", sizeof(m_PlayerRequest.m_aServer)); str_copy(m_PlayerRequest.m_aServer, "USA", sizeof(m_PlayerRequest.m_aServer));
ASSERT_FALSE(CScoreWorker::ShowRank(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError; ASSERT_FALSE(CScoreWorker::ShowRank(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError;
ExpectLines(m_pPlayerResult, {"nameless tee - 01:40.00 - requested by brainless tee", "Global rank 1"}, true); ExpectLines(m_pPlayerResult, {"nameless tee - 01:40.00 - better than 100% - requested by brainless tee", "Global rank 1"}, true);
} }
TEST_P(SingleScore, LoadPlayerData) TEST_P(SingleScore, LoadPlayerData)