Skip to content

Commit a590938

Browse files
committed
lint
1 parent 1719b88 commit a590938

4 files changed

Lines changed: 19 additions & 21 deletions

File tree

src/database/database.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ void Database::connect_to_db() {
8585
"timestamp TIMESTAMPTZ DEFAULT NOW(), "
8686
"PRIMARY KEY (id, game_id)"
8787
");");
88-
txn.exec(
89-
"CREATE INDEX IF NOT EXISTS idx_peers_peer_game ON peers (peer_id, game_id);");
88+
txn.exec("CREATE INDEX IF NOT EXISTS idx_peers_peer_game ON peers (peer_id, game_id);");
9089
txn.commit();
9190
} catch (const std::exception& e) {
9291
std::cerr << e.what() << std::endl;
@@ -148,7 +147,7 @@ void Database::set_user_data(const std::string& game_id, const std::string& peer
148147
std::string name;
149148
auto it = user_data.find("n");
150149
if (it != user_data.end()) {
151-
const AnyElement &nElem = it->second;
150+
const AnyElement& nElem = it->second;
152151
if (std::holds_alternative<std::string>(nElem.value)) {
153152
name = std::get<std::string>(nElem.value);
154153
}
@@ -170,15 +169,14 @@ std::vector<std::tuple<std::string, int64_t, std::string>> Database::leaderboard
170169
ensure_connection();
171170
pqxx::work txn(*connection);
172171
// Prefer the latest known name for the peer (fall back to user_id)
173-
pqxx::result r = txn.exec(
174-
pqxx::zview(
175-
"SELECT COALESCE(p.name, '') AS display_name, l.score, "
176-
"to_char(l.timestamp, 'YYYY-MM-DDHH24:MI:SS') "
177-
"FROM leaderboards l "
178-
"LEFT JOIN peers p ON p.peer_id = l.user_id AND p.game_id = l.game_id "
179-
"WHERE l.leaderboard_id = $1 AND l.game_id = $2 "
180-
"ORDER BY l.score DESC LIMIT $3 OFFSET $4;"),
181-
pqxx::params(leaderboard_id, game_id, limit, start));
172+
pqxx::result r =
173+
txn.exec(pqxx::zview("SELECT COALESCE(p.name, '') AS display_name, l.score, "
174+
"to_char(l.timestamp, 'YYYY-MM-DDHH24:MI:SS') "
175+
"FROM leaderboards l "
176+
"LEFT JOIN peers p ON p.peer_id = l.user_id AND p.game_id = l.game_id "
177+
"WHERE l.leaderboard_id = $1 AND l.game_id = $2 "
178+
"ORDER BY l.score DESC LIMIT $3 OFFSET $4;"),
179+
pqxx::params(leaderboard_id, game_id, limit, start));
182180
std::vector<std::tuple<std::string, int64_t, std::string>> results;
183181
for (auto row : r) {
184182
results.emplace_back(row[0].as<std::string>(), row[1].as<int64_t>(),
@@ -196,12 +194,11 @@ std::tuple<int64_t, int, std::string, std::string> Database::leaderboard_get_use
196194

197195
// Get score, timestamp, and optional name
198196
pqxx::result r =
199-
txn.exec(pqxx::zview(
200-
"SELECT l.score, l.timestamp, p.name "
201-
"FROM leaderboards l "
202-
"LEFT JOIN peers p ON p.peer_id = l.user_id AND p.game_id = l.game_id "
203-
"WHERE l.leaderboard_id = $1 AND l.game_id = $2 AND l.user_id = $3;"),
204-
pqxx::params(leaderboard_id, game_id, user_id));
197+
txn.exec(pqxx::zview("SELECT l.score, l.timestamp, p.name "
198+
"FROM leaderboards l "
199+
"LEFT JOIN peers p ON p.peer_id = l.user_id AND p.game_id = l.game_id "
200+
"WHERE l.leaderboard_id = $1 AND l.game_id = $2 AND l.user_id = $3;"),
201+
pqxx::params(leaderboard_id, game_id, user_id));
205202

206203
int64_t score = r.empty() ? 0 : r[0][0].as<int64_t>();
207204
std::string timestamp = r.empty() ? "" : r[0][1].as<std::string>();

src/database/database.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Database {
1818
std::string get_peer_or_insert(const std::string& reconnection_token,
1919
const std::string& game_id, const std::string& peer_id);
2020
void set_user_data(const std::string& game_id, const std::string& peer_id,
21-
const std::map<std::string, AnyElement>& user_data);
21+
const std::map<std::string, AnyElement>& user_data);
2222
std::vector<std::tuple<std::string, int64_t, std::string>> leaderboard_get_top(
2323
const std::string& leaderboard_id, const std::string& game_id, int limit, int start);
2424
std::tuple<int64_t, int, std::string> leaderboard_get_user_score(

src/database/database_thread.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#include <readerwriterqueue.h>
33

44
#include <atomic>
5+
#include <boost/container/flat_map.hpp>
56
#include <functional>
67
#include <string>
78
#include <thread>
89
#include <variant>
910
#include <vector>
10-
#include <boost/container/flat_map.hpp>
11+
1112
#include "../common/any_type.h"
1213

1314
// Define a struct for database tasks/messages

src/game/game_thread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void GameThread::run() {
168168
// if time has not changed, sleep for a bit
169169
if (last_time == now) {
170170
std::this_thread::sleep_for(std::chrono::milliseconds(5));
171-
//continue;
171+
// continue;
172172
}
173173
// handle disconnects
174174
if (now - last_disconnect > disconnect_interval) {

0 commit comments

Comments
 (0)