From 498959b6c924844ca1af3451ba906881d71982d7 Mon Sep 17 00:00:00 2001 From: Giuseppe Guerra Date: Fri, 18 Sep 2020 23:21:23 +0200 Subject: [PATCH] "Fix" replay buckets not being chosen correctly --- helpers/s3.py | 14 ++++++++++---- version | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/helpers/s3.py b/helpers/s3.py index 363a0bb0..37ab1018 100644 --- a/helpers/s3.py +++ b/helpers/s3.py @@ -19,11 +19,17 @@ def getWriteReplayBucketName(): def getReadReplayBucketName(scoreID): r = objects.glob.db.fetch( - "SELECT `name`, max_score_id FROM s3_replay_buckets WHERE max_score_id IS NOT NULL " - "ORDER BY abs(max_score_id - %s) LIMIT 1", - (scoreID,) + """SELECT name FROM ( + SELECT `name`, + IFNULL((SELECT max_score_id + 1 FROM s3_replay_buckets WHERE id = x.id - 1), 0) AS min_score_id, + IFNULL(max_score_id, ~0) AS max_score_id + FROM s3_replay_buckets AS x + ) AS x + WHERE %s > min_score_id AND %s < max_score_id + LIMIT 1""", + (scoreID, scoreID) ) - if r is not None and scoreID <= r["max_score_id"]: + if r is not None: log.debug("s3 replay buckets resolve: {} -> {}".format(scoreID, r["name"])) return r["name"] log.debug("s3 replay buckets resolve: {} -> WRITE BUCKET".format(scoreID)) diff --git a/version b/version index 08002f86..457f0385 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.27.1 +1.27.2