Fix critical bugs: touchEnabled undefined, MongoDB score sorting with score_value field

This commit is contained in:
2026-01-15 23:39:12 +08:00
parent d6a1b6bd41
commit 76a3d52098
2 changed files with 11 additions and 7 deletions

15
app.py
View File

@@ -105,7 +105,7 @@ db.users.create_index('username', unique=True)
db.songs.create_index('id', unique=True) db.songs.create_index('id', unique=True)
db.songs.create_index('song_type') db.songs.create_index('song_type')
db.scores.create_index('username') db.scores.create_index('username')
db.leaderboards.create_index([('song_id', 1), ('difficulty', 1), ('month', 1), ('score', -1)]) db.leaderboards.create_index([('song_id', 1), ('difficulty', 1), ('month', 1), ('score_value', -1)])
db.leaderboards.create_index([('song_id', 1), ('difficulty', 1), ('username', 1), ('month', 1)], unique=True) db.leaderboards.create_index([('song_id', 1), ('difficulty', 1), ('username', 1), ('month', 1)], unique=True)
db.leaderboards.create_index('month') db.leaderboards.create_index('month')
@@ -795,12 +795,13 @@ def route_api_leaderboard_submit():
if existing: if existing:
# Update only if new score is higher # Update only if new score is higher
existing_score = int(existing.get('score', {}).get('score', 0)) existing_score = existing.get('score_value', 0)
if score_value > existing_score: if score_value > existing_score:
db.leaderboards.update_one( db.leaderboards.update_one(
{'_id': existing['_id']}, {'_id': existing['_id']},
{'$set': { {'$set': {
'score': score_data, 'score': score_data,
'score_value': score_value,
'display_name': user['display_name'], 'display_name': user['display_name'],
'submitted_at': time.time() 'submitted_at': time.time()
}} }}
@@ -822,10 +823,10 @@ def route_api_leaderboard_submit():
'song_id': song_id, 'song_id': song_id,
'difficulty': difficulty, 'difficulty': difficulty,
'month': current_month 'month': current_month
}).sort('score', -1).limit(50)) }).sort('score_value', -1).limit(50))
if len(leaderboard) >= 50: if len(leaderboard) >= 50:
last_score = int(leaderboard[49].get('score', {}).get('score', 0)) last_score = leaderboard[49].get('score_value', 0)
if score_value <= last_score: if score_value <= last_score:
return jsonify({'status': 'ok', 'message': 'score_too_low'}) return jsonify({'status': 'ok', 'message': 'score_too_low'})
@@ -836,6 +837,7 @@ def route_api_leaderboard_submit():
'username': username, 'username': username,
'display_name': user['display_name'], 'display_name': user['display_name'],
'score': score_data, 'score': score_data,
'score_value': score_value,
'submitted_at': time.time(), 'submitted_at': time.time(),
'month': current_month 'month': current_month
}) })
@@ -847,7 +849,7 @@ def route_api_leaderboard_submit():
'song_id': song_id, 'song_id': song_id,
'difficulty': difficulty, 'difficulty': difficulty,
'month': current_month 'month': current_month
}).sort('score', -1)) }).sort('score_value', -1))
# Delete entries beyond 50 # Delete entries beyond 50
if len(all_entries) > 50: if len(all_entries) > 50:
@@ -888,8 +890,9 @@ def route_api_leaderboard_get():
'username': True, 'username': True,
'display_name': True, 'display_name': True,
'score': True, 'score': True,
'score_value': True,
'submitted_at': True 'submitted_at': True
}).sort('score', -1).limit(50)) }).sort('score_value', -1).limit(50))
# Add rank to each entry # Add rank to each entry
for i, entry in enumerate(leaderboard): for i, entry in enumerate(leaderboard):

View File

@@ -130,8 +130,9 @@ class Leaderboard {
assets.sounds["se_cancel"].play() assets.sounds["se_cancel"].play()
// Return to song select // Return to song select - get touchEnabled from global or default to false
setTimeout(() => { setTimeout(() => {
var touchEnabled = typeof window.touchEnabled !== 'undefined' ? window.touchEnabled : false
new SongSelect(false, false, touchEnabled) new SongSelect(false, false, touchEnabled)
}, 100) }, 100)
} }