mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-02 20:08:17 +03:00
Merge pull request #571 from TNG-dev:zkldi/issue-569
Add an IsPrimary update script, and make it run if charts change.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
import UpdateIsPrimaryStatus from "lib/score-mutation/update-isprimary";
|
||||
|
||||
UpdateIsPrimaryStatus().then(() => process.exit(0));
|
||||
@@ -6,6 +6,7 @@ import { monkDB } from "external/mongo/db";
|
||||
import fjsh from "fast-json-stable-hash";
|
||||
import fs from "fs";
|
||||
import CreateLogCtx, { KtLogger } from "lib/logger/logger";
|
||||
import UpdateIsPrimaryStatus from "lib/score-mutation/update-isprimary";
|
||||
import { TachiConfig } from "lib/setup/config";
|
||||
import { BulkWriteOperation } from "mongodb";
|
||||
import { ICollection } from "monk";
|
||||
@@ -128,6 +129,7 @@ const syncInstructions: SyncInstructions[] = [
|
||||
|
||||
if (r) {
|
||||
await InitaliseFolderChartLookup();
|
||||
await UpdateIsPrimaryStatus();
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import db from "external/mongo/db";
|
||||
import { TachiConfig } from "lib/setup/config";
|
||||
|
||||
export default async function UpdateIsPrimaryStatus() {
|
||||
for (const game of TachiConfig.GAMES) {
|
||||
const chartIDs = (
|
||||
await db.charts[game].find({
|
||||
isPrimary: false,
|
||||
})
|
||||
).map((e) => e.chartID);
|
||||
|
||||
await db.scores.update(
|
||||
{
|
||||
chartID: { $in: chartIDs },
|
||||
},
|
||||
{ $set: { isPrimary: false } }
|
||||
);
|
||||
|
||||
await db["personal-bests"].update(
|
||||
{
|
||||
chartID: { $in: chartIDs },
|
||||
},
|
||||
{ $set: { isPrimary: false } }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// The easier way to do this is just to always update the isPrimary status
|
||||
// Left, for posterities sake, is an incredibly sub-optimal aggregate that
|
||||
// achieves this also.
|
||||
//
|
||||
// const scores = await db.scores.aggregate([
|
||||
// {
|
||||
// $match: {
|
||||
// game: "iidx",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// $lookup: {
|
||||
// from: "charts-iidx",
|
||||
// localField: "chartID",
|
||||
// foreignField: "chartID",
|
||||
// as: "chart",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// $unwind: {
|
||||
// path: "$chart",
|
||||
// },
|
||||
// },
|
||||
// // This is the best way to do $match $ne, according to SO.
|
||||
// {
|
||||
// $addFields: {
|
||||
// needsUpdate: {
|
||||
// $ne: ["$chart.isPrimary", "$isPrimary"],
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// $match: {
|
||||
// needsUpdate: true,
|
||||
// },
|
||||
// },
|
||||
// ]);
|
||||
Reference in New Issue
Block a user