mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-01 03:18:06 +03:00
fix: sort scores with no timestamps behind scores with one (#1389)
This commit is contained in:
@@ -6,7 +6,7 @@ import { GetEveryonesRivalIDs } from "lib/rivals/rivals";
|
||||
import { GetGPTConfig, GetGamePTConfig } from "tachi-common";
|
||||
import { DeleteUndefinedProps } from "utils/misc";
|
||||
import type { KtLogger } from "lib/logger/logger";
|
||||
import type { BulkWriteUpdateOneOperation, FilterQuery } from "mongodb";
|
||||
import type { BulkWriteUpdateOneOperation, FilterQuery, SortOptionObject } from "mongodb";
|
||||
import type {
|
||||
GPTString,
|
||||
Game,
|
||||
@@ -179,27 +179,45 @@ export async function UpdateChartRanking(game: Game, playtype: Playtype, chartID
|
||||
|
||||
async function GetSortedPBs(game: Game, playtype: Playtype, chartID: string) {
|
||||
const gptConfig = GetGamePTConfig(game, playtype);
|
||||
let sortOptions: SortOptionObject<PBScoreDocument> = {
|
||||
[`scoreData.${gptConfig.defaultMetric}`]: -1,
|
||||
};
|
||||
|
||||
if (game === "ongeki") {
|
||||
return db["personal-bests"].find(
|
||||
{ chartID },
|
||||
{
|
||||
sort: {
|
||||
[`scoreData.score`]: -1,
|
||||
[`scoreData.platinumScore`]: -1,
|
||||
timeAchieved: 1,
|
||||
},
|
||||
}
|
||||
);
|
||||
sortOptions = {
|
||||
[`scoreData.score`]: -1,
|
||||
[`scoreData.platinumScore`]: -1,
|
||||
};
|
||||
}
|
||||
|
||||
return db["personal-bests"].find(
|
||||
{ chartID },
|
||||
return db["personal-bests"].aggregate([
|
||||
{
|
||||
sort: {
|
||||
[`scoreData.${gptConfig.defaultMetric}`]: -1,
|
||||
$match: {
|
||||
chartID,
|
||||
},
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
hasTimeAchieved: {
|
||||
$cond: {
|
||||
if: { $eq: ["$timeAchieved", null] },
|
||||
then: false,
|
||||
else: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
...sortOptions,
|
||||
hasTimeAchieved: -1,
|
||||
timeAchieved: 1,
|
||||
},
|
||||
}
|
||||
);
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
hasTimeAchieved: 0,
|
||||
},
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user