From 00586a0c4a29b9c072d28451aed463472b3f5a92 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Thu, 8 Aug 2024 18:59:10 +0200 Subject: [PATCH] Revert "Faster /rank, fixes test result" This reverts commit c2a3444f87c32f2a7d868efd7fe402bfac7ebfda. --- src/game/server/scoreworker.cpp | 39 ++++++++++++--------------------- src/test/score.cpp | 8 +++---- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/game/server/scoreworker.cpp b/src/game/server/scoreworker.cpp index db6fece9f..a225ec296 100644 --- a/src/game/server/scoreworker.cpp +++ b/src/game/server/scoreworker.cpp @@ -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) " + "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) as minTime " - "FROM %s_race " - "WHERE Map = ? " - "AND Server LIKE ? " - "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()); + " WINDOW w AS (ORDER BY MIN(Time))" + ") as a " + "WHERE Name = ?", + pSqlServer->GetPrefix()); 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(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)) @@ -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 { @@ -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) diff --git a/src/test/score.cpp b/src/test/score.cpp index c6f8e80c4..d64bd6f37 100644 --- a/src/test/score.cpp +++ b/src/test/score.cpp @@ -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) @@ -205,7 +205,7 @@ 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) @@ -213,7 +213,7 @@ 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)