Merge pull request #537 from TNG-dev/zkldi/issue-526

This commit is contained in:
zkldi
2021-12-06 20:31:34 +00:00
committed by GitHub
3 changed files with 31 additions and 5 deletions
+4 -3
View File
@@ -10,6 +10,7 @@ import {
SongDocument,
} from "tachi-common";
import { GetNextCounterValue } from "utils/db";
import { DedupeArr } from "utils/misc";
const logger = CreateLogCtx(__filename);
@@ -35,7 +36,7 @@ export async function HandleOrphanQueue<I extends IDStrings>(
userID: integer,
chartName: string
) {
logger.debug(`received orphanqueue request for ${chartName}.`);
logger.debug(`Received orphanqueue request for ${chartName}.`);
const orphanChart = await db["orphan-chart-queue"].findOne(
Object.assign({ idString }, orphanMatchCriteria),
@@ -45,7 +46,7 @@ export async function HandleOrphanQueue<I extends IDStrings>(
);
if (!orphanChart) {
logger.verbose(`received unknown chart ${chartName}, orphaning.`);
logger.verbose(`Received unknown chart ${chartName}, orphaning.`);
await db["orphan-chart-queue"].insert({
idString,
@@ -59,7 +60,7 @@ export async function HandleOrphanQueue<I extends IDStrings>(
orphanChart.userIDs.push(userID);
const uniqueUsersArr = [...new Set(orphanChart.userIDs)];
const uniqueUsersArr = DedupeArr(orphanChart.userIDs);
const playcount = uniqueUsersArr.length;
// If N or more people have played this chart while orphaned, unorphan
@@ -582,6 +582,12 @@ t.test("POST /scores", (t) => {
t.equal(res.body.statusCode, 22);
t.match(
res.body.description,
"(1/3)",
"Should contain (required/outOf) in the response description."
);
const dbScore = await db.scores.findOne({
game: "usc",
});
@@ -21,6 +21,7 @@ import {
Playtypes,
SuccessfulAPIResponse,
} from "tachi-common";
import { DedupeArr } from "utils/misc";
import { FormatPrError } from "utils/prudence";
import { GetBlacklist } from "utils/queries/blacklist";
import { AssignToReqTachiData } from "utils/req-tachi-data";
@@ -319,6 +320,7 @@ router.post("/scores", RequirePermissions("submit_score"), async (req, res) => {
song,
{
"chartDoc.data.hashSHA1": uscChart.chartHash,
"chartDoc.playtype": playtype,
},
ServerConfig.USC_QUEUE_SIZE,
req[SYMBOL_TachiAPIAuth].userID!,
@@ -349,10 +351,27 @@ router.post("/scores", RequirePermissions("submit_score"), async (req, res) => {
// If this was an orphan chart request, return ACCEPTED,
// since it may be unorphaned in the future
if (!chartDoc) {
const orphanChart = await db["orphan-chart-queue"].findOne({
"chartDoc.data.hashSHA1": uscChart.chartHash,
"chartDoc.playtype": playtype,
});
if (!orphanChart) {
logger.severe(
`No orphan chart for USC ${uscChart.chartHash} (${playtype})? One was expected.`,
{ uscChart, playtype }
);
return res.status(200).json({
statusCode: STATUS_CODES.SERVER_ERROR,
description: `An internal server error has occured.`,
});
}
const players = DedupeArr([...orphanChart.userIDs, userID]);
return res.status(200).json({
statusCode: STATUS_CODES.ACCEPTED,
description:
"This score has been accepted, but is waiting for more players before its parent chart is accepted.",
description: `This score has been accepted, but is waiting for more players before its parent chart is accepted. (${players.length}/${ServerConfig.USC_QUEUE_SIZE})`,
});
}