Skip to content

Commit

Permalink
Revert "Faster /rank, fixes test result"
Browse files Browse the repository at this point in the history
This reverts commit c2a3444.
  • Loading branch information
def- committed Aug 8, 2024
1 parent e3dd289 commit 00586a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
39 changes: 14 additions & 25 deletions src/game/server/scoreworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,25 +786,17 @@ bool CScoreWorker::ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData
// check sort method
char aBuf[600];
str_format(aBuf, sizeof(aBuf),
"SELECT COUNT(DISTINCT Name) + 1 AS Ranking, (SELECT MIN(Time) "
" FROM %s_race "
" WHERE Map = ? "
" AND Server LIKE ? "
" AND Name = ? "
" GROUP BY Name "
" LIMIT 1) as minTime "
"FROM %s_race "
"WHERE Map = ? "
"AND Server LIKE ? "
"AND Time < (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 "
" WHERE Map = ? "
" AND Server LIKE ? "
" AND Name = ? "
" GROUP BY Name "
" LIMIT 1 "
") ",
pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix());
" WINDOW w AS (ORDER BY MIN(Time))"
") as a "
"WHERE Name = ?",
pSqlServer->GetPrefix());

if(pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
{
Expand All @@ -813,11 +805,6 @@ bool CScoreWorker::ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData
pSqlServer->BindString(1, pData->m_aMap);
pSqlServer->BindString(2, aServerLike);
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;
if(pSqlServer->Step(&End, pError, ErrorSize))
Expand Down Expand Up @@ -854,11 +841,13 @@ bool CScoreWorker::ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData
{
int Rank = pSqlServer->GetInt(1);
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));
if(g_Config.m_SvHideScore)
{
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
{
Expand All @@ -867,14 +856,14 @@ bool CScoreWorker::ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData
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]),
"%s - %s",
pData->m_aName, aBuf);
"%s - %s - better than %d%%",
pData->m_aName, aBuf, BetterThanPercent);
}
else
{
str_format(pResult->m_Data.m_aaMessages[0], sizeof(pResult->m_Data.m_aaMessages[0]),
"%s - %s - requested by %s",
pData->m_aName, aBuf, pData->m_aRequestingPlayer);
"%s - %s - better than %d%% - requested by %s",
pData->m_aName, aBuf, BetterThanPercent, pData->m_aRequestingPlayer);
}

if(g_Config.m_SvRegionalRankings)
Expand Down
8 changes: 4 additions & 4 deletions src/test/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ TEST_P(SingleScore, RankRegional)
{
g_Config.m_SvRegionalRankings = true;
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)
{
g_Config.m_SvRegionalRankings = false;
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)
Expand Down Expand Up @@ -205,15 +205,15 @@ TEST_P(SingleScore, RankServerRegional)
g_Config.m_SvRegionalRankings = true;
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;
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)
{
g_Config.m_SvRegionalRankings = false;
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;
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)
Expand Down

0 comments on commit 00586a0

Please sign in to comment.