Skip to content

Commit 06c8a1a

Browse files
committed
move logging to middleware;key names
1 parent d78628b commit 06c8a1a

8 files changed

Lines changed: 25 additions & 87 deletions

File tree

surftimer/ck_bonus.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
from pydantic import BaseModel
44
from sql import selectQuery, insertQuery
55
from globals import (
6-
redis_client,
7-
config,
8-
append_request_log,
96
set_cache,
107
get_cache,
118
)
@@ -48,7 +45,6 @@ def insertBonus(
4845
"""Inserts a new record to the table\n
4946
```char sql_insertLatestRecords[] = ....```"""
5047
tic = time.perf_counter()
51-
append_request_log(request)
5248

5349
sql = surftimer.queries.sql_insertBonus.format(
5450
data.steamid32,
@@ -73,7 +69,6 @@ def insertBonus(
7369
# Prepare the response
7470
toc = time.perf_counter()
7571
print(f"Execution time {toc - tic:0.4f}")
76-
# output = ResponseInsertQuery(xquery)
7772

7873
return {"inserted": xquery, "xtime": time.perf_counter() - tic}
7974

@@ -90,7 +85,6 @@ def updateBonus(
9085
):
9186
"""```char sql_updateBonus[] = ....```"""
9287
tic = time.perf_counter()
93-
append_request_log(request)
9488

9589
sql = surftimer.queries.sql_updateBonus.format(
9690
data.runtime,
@@ -127,10 +121,8 @@ def selectBonusCount(request: Request, response: Response, mapname: str):
127121
```char sql_selectBonusCount[] = ....```"""
128122
tic = time.perf_counter()
129123

130-
append_request_log(request)
131-
132124
# Check if data is cached in Redis
133-
cache_key = f"selectBonusCount_{mapname}"
125+
cache_key = f"selectBonusCount:{mapname}"
134126
cached_data = get_cache(cache_key)
135127
if cached_data:
136128
print(f"[Redis] Loaded '{cache_key}' ({time.perf_counter() - tic:0.4f}s)")
@@ -166,8 +158,6 @@ def selectPersonalBonusRecords(
166158
"""```char sql_selectPersonalBonusRecords[] = ....```"""
167159
tic = time.perf_counter()
168160

169-
append_request_log(request)
170-
171161
# Check if data is cached in Redis
172162
cache_key = f"selectPersonalBonusRecords:{steamid32}-{mapname}"
173163
cached_data = get_cache(cache_key)
@@ -211,7 +201,6 @@ def selectPlayerRankBonus(
211201
"""```char sql_selectPlayerRankBonus[] = ....```"""
212202
tic = time.perf_counter()
213203

214-
append_request_log(request)
215204
cache_key = (
216205
f"selectPlayerRankBonus:{data.steamid32}-{data.mapname}-{data.zonegroup}"
217206
)
@@ -262,8 +251,6 @@ def selectFastestBonus(
262251
"""```char sql_selectFastestBonus[] = ....```"""
263252
tic = time.perf_counter()
264253

265-
append_request_log(request)
266-
267254
# Check if data is cached in Redis
268255
cache_key = f"selectFastestBonus:{mapname}"
269256
cached_data = get_cache(cache_key)
@@ -303,8 +290,6 @@ def selectAllBonusTimesinMap(
303290
"""```char sql_selectAllBonusTimesinMap[] = ....```"""
304291
tic = time.perf_counter()
305292

306-
append_request_log(request)
307-
308293
# Check if data is cached in Redis
309294
cache_key = f"selectAllBonusTimesinMap:{mapname}"
310295
cached_data = get_cache(cache_key)
@@ -346,8 +331,6 @@ def selectTopBonusSurfers(
346331
"""```char sql_selectTopBonusSurfers[] = ....```"""
347332
tic = time.perf_counter()
348333

349-
append_request_log(request)
350-
351334
# Check if data is cached in Redis
352335
cache_key = f"selectTopBonusSurfers:{mapname}-{style}-{zonegroup}"
353336
cached_data = get_cache(cache_key)
@@ -394,8 +377,6 @@ def deleteBonus(
394377
"""```char sql_deleteBonus[] = ....```"""
395378
tic = time.perf_counter()
396379

397-
append_request_log(request)
398-
399380
xquery = insertQuery(surftimer.queries.sql_deleteBonus.format(mapname))
400381

401382
if xquery <= 0:

surftimer/ck_checkpoints.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastapi import APIRouter, Request, Response, status
22
from fastapi.responses import JSONResponse
33
from sql import selectQuery, insertQuery
4-
from globals import append_request_log, get_cache, set_cache
4+
from globals import get_cache, set_cache
55
from pydantic import BaseModel
66
import time, json, surftimer.queries
77

@@ -31,7 +31,6 @@ async def insertOrUpdateCheckpoints(
3131
data: PlayerCheckpoints,
3232
):
3333
tic = time.perf_counter()
34-
append_request_log(request)
3534

3635
sql = surftimer.queries.sql_InsertOrUpdateCheckpoints.format(
3736
data.steamid,
@@ -56,7 +55,6 @@ async def insertOrUpdateCheckpoints(
5655
# Prepare the response
5756
toc = time.perf_counter()
5857
print(f"Execution time {toc - tic:0.4f}")
59-
# output = ResponseInsertQuery(xquery)
6058

6159
return {"inserted": xquery, "xtime": time.perf_counter() - tic}
6260

@@ -71,7 +69,6 @@ async def selectCheckpoints(
7169
):
7270
"""`char[] sql_selectCheckpoints = ....`"""
7371
tic = time.perf_counter()
74-
append_request_log(request)
7572

7673
# Check if data is cached in Redis
7774
cache_key = f"selectCheckpoints:{mapname}-{steamid32}"
@@ -117,7 +114,6 @@ async def selectCheckpointsinZoneGroup(
117114
):
118115
"""`char[] sql_selectCheckpointsinZoneGroup = ....`"""
119116
tic = time.perf_counter()
120-
append_request_log(request)
121117

122118
# Check if data is cached in Redis
123119
cache_key = f"selectCheckpointsinZoneGroup:{mapname}-{steamid32}-{zonegroup}"
@@ -160,7 +156,6 @@ async def selectRecordCheckpoints(
160156
):
161157
"""`char[] sql_selectRecordCheckpoints = ....`"""
162158
tic = time.perf_counter()
163-
append_request_log(request)
164159

165160
# Check if data is cached in Redis
166161
cache_key = f"selectRecordCheckpoints:{steamid32}-{mapname}-{mapname}"
@@ -206,8 +201,6 @@ async def deleteCheckpoints(
206201
"""```char sql_deleteCheckpoints[] = ....```"""
207202
tic = time.perf_counter()
208203

209-
append_request_log(request)
210-
211204
xquery = insertQuery(surftimer.queries.sql_deleteCheckpoints.format(mapname))
212205

213206
if xquery <= 0:
@@ -232,7 +225,6 @@ async def selectStageTimes(
232225
):
233226
"""`char[] sql_selectStageTimes = ....`"""
234227
tic = time.perf_counter()
235-
append_request_log(request)
236228

237229
# Check if data is cached in Redis
238230
cache_key = f"selectStageTimes:-{mapname}-{steamid32}"
@@ -273,7 +265,6 @@ async def selectStageAttempts(
273265
):
274266
"""`char[] sql_selectStageAttempts = ....`"""
275267
tic = time.perf_counter()
276-
append_request_log(request)
277268

278269
# Check if data is cached in Redis
279270
cache_key = f"selectStageAttempts:-{mapname}-{steamid32}"

surftimer/ck_latestrecords.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastapi import APIRouter, Request, Response, status
22
from fastapi.responses import JSONResponse
33
from sql import selectQuery, insertQuery
4-
from globals import append_request_log, get_cache, set_cache
4+
from globals import get_cache, set_cache
55
import time, json
66
import surftimer.queries
77

@@ -19,8 +19,6 @@ async def selectLatestRecord(request: Request, response: Response):
1919
```char sql_selectLatestRecords[] = ....```"""
2020
tic = time.perf_counter()
2121

22-
append_request_log(request)
23-
2422
# Check if data is cached in Redis
2523
cache_key = f"selectLatestRecord"
2624
cached_data = get_cache(cache_key)
@@ -65,7 +63,6 @@ async def insertLatestRecord(
6563
"""Inserts a new record to the table\n
6664
```char sql_insertLatestRecords[] = ....```"""
6765
tic = time.perf_counter()
68-
append_request_log(request)
6966

7067
sql = surftimer.queries.sql_insertLatestRecords.format(
7168
steamid32, name, runtime, mapname

surftimer/ck_maptier.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastapi import APIRouter, Request, Response, status
22
from fastapi.responses import JSONResponse
33
from sql import selectQuery, insertQuery
4-
from globals import redis_client, config, append_request_log, get_cache, set_cache
4+
from globals import get_cache, set_cache
55
import time, json
66
import surftimer.queries
77

@@ -21,10 +21,9 @@ async def selectMapTier(
2121
):
2222
"""`char[] sql_selectMapTier = ....`"""
2323
tic = time.perf_counter()
24-
append_request_log(request)
2524

2625
# Check if data is cached in Redis
27-
cache_key = f"selectMapTier_{mapname}"
26+
cache_key = f"selectMapTier:{mapname}"
2827
cached_data = get_cache(cache_key)
2928
if cached_data is not None:
3029
print(f"[Redis] Loaded '{cache_key}' ({time.perf_counter() - tic:0.4f}s)")
@@ -49,7 +48,7 @@ async def selectMapTier(
4948
toc = time.perf_counter()
5049

5150
print(f"Execution time {toc - tic:0.4f}")
52-
51+
5352
return xquery
5453

5554

@@ -68,7 +67,6 @@ async def insertMapTier(
6867
char[] sql_insertmaptier = ....
6968
```"""
7069
tic = time.perf_counter()
71-
append_request_log(request)
7270

7371
xquery = insertQuery(surftimer.queries.sql_insertmaptier.format(mapname, tier))
7472

@@ -81,7 +79,6 @@ async def insertMapTier(
8179
# Prepare the response
8280
toc = time.perf_counter()
8381
print(f"Execution time {toc - tic:0.4f}")
84-
# output = ResponseInsertQuery(xquery)
8582

8683
return {"inserted": xquery, "xtime": time.perf_counter() - tic}
8784

@@ -101,7 +98,6 @@ async def updateMapTier(
10198
char[] sql_updatemaptier = ....
10299
```"""
103100
tic = time.perf_counter()
104-
append_request_log(request)
105101

106102
xquery = insertQuery(surftimer.queries.sql_updatemaptier.format(tier, mapname))
107103

@@ -114,7 +110,6 @@ async def updateMapTier(
114110
# Prepare the response
115111
toc = time.perf_counter()
116112
print(f"Execution time {toc - tic:0.4f}")
117-
# output = ResponseInsertQuery(xquery)
118113

119114
return {"updated": xquery, "xtime": time.perf_counter() - tic}
120115

@@ -134,7 +129,6 @@ async def updateMapperName(
134129
char[] sql_updateMapperName = ....
135130
```"""
136131
tic = time.perf_counter()
137-
append_request_log(request)
138132

139133
xquery = insertQuery(surftimer.queries.sql_updateMapperName.format(mapper, mapname))
140134

@@ -147,6 +141,5 @@ async def updateMapperName(
147141
# Prepare the response
148142
toc = time.perf_counter()
149143
print(f"Execution time {toc - tic:0.4f}")
150-
# output = ResponseInsertQuery(xquery)
151144

152145
return {"inserted": xquery, "xtime": time.perf_counter() - tic}

surftimer/ck_playeroptions2.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastapi import APIRouter, Request, Response, status
22
from fastapi.responses import JSONResponse
33
from sql import selectQuery, insertQuery
4-
from globals import append_request_log, get_cache, set_cache
4+
from globals import get_cache, set_cache
55
from pydantic import BaseModel
66
import time, json, surftimer.queries
77

@@ -59,7 +59,6 @@ async def insertPlayerOptions(request: Request, response: Response, steamid32: s
5959
char[] sql_insertPlayerOptions = ....
6060
```"""
6161
tic = time.perf_counter()
62-
append_request_log(request)
6362

6463
xquery = insertQuery(surftimer.queries.sql_insertPlayerOptions.format(steamid32))
6564

@@ -72,7 +71,6 @@ async def insertPlayerOptions(request: Request, response: Response, steamid32: s
7271
# Prepare the response
7372
toc = time.perf_counter()
7473
print(f"Execution time {toc - tic:0.4f}")
75-
# output = ResponseInsertQuery(xquery)
7674

7775
return {"inserted": xquery, "xtime": time.perf_counter() - tic}
7876

@@ -85,10 +83,9 @@ async def insertPlayerOptions(request: Request, response: Response, steamid32: s
8583
async def selectPlayerOptions(request: Request, response: Response, steamid32: str):
8684
"""`char[] sql_selectPlayerOptions = ....`"""
8785
tic = time.perf_counter()
88-
append_request_log(request)
8986

9087
# Check if data is cached in Redis
91-
cache_key = f"selectPlayerOptions_{steamid32}"
88+
cache_key = f"selectPlayerOptions:{steamid32}"
9289
cached_data = get_cache(cache_key)
9390
if cached_data is not None:
9491
print(f"[Redis] Loaded '{cache_key}' ({time.perf_counter() - tic:0.4f}s)")
@@ -119,12 +116,13 @@ async def selectPlayerOptions(request: Request, response: Response, steamid32: s
119116
name="Update Player Options",
120117
tags=["ck_playeroptions2"],
121118
)
122-
async def updatePlayerOptions(request: Request, response: Response, data: PlayerOptions):
119+
async def updatePlayerOptions(
120+
request: Request, response: Response, data: PlayerOptions
121+
):
123122
"""```c
124123
char[] sql_updatePlayerOptions = ....
125124
```"""
126125
tic = time.perf_counter()
127-
append_request_log(request)
128126

129127
xquery = insertQuery(
130128
surftimer.queries.sql_updatePlayerOptions.format(
@@ -176,6 +174,5 @@ async def updatePlayerOptions(request: Request, response: Response, data: Player
176174
# Prepare the response
177175
toc = time.perf_counter()
178176
print(f"Execution time {toc - tic:0.4f}")
179-
# output = ResponseInsertQuery(xquery)
180177

181178
return {"updated": xquery, "xtime": time.perf_counter() - tic}

0 commit comments

Comments
 (0)