mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-06 05:48:00 +03:00
feat: add goal sync support
This commit is contained in:
@@ -14,12 +14,16 @@ import {
|
||||
ChartDocument,
|
||||
FolderDocument,
|
||||
Game,
|
||||
GoalDocument,
|
||||
MilestoneDocument,
|
||||
MilestoneSetDocument,
|
||||
SongDocument,
|
||||
TableDocument,
|
||||
} from "tachi-common";
|
||||
import { RecalcAllScores } from "utils/calculations/recalc-scores";
|
||||
import { UpdateGameSongIDCounter } from "utils/db";
|
||||
import { InitaliseFolderChartLookup } from "utils/folder";
|
||||
import { IsSupported } from "utils/misc";
|
||||
|
||||
interface SyncInstructions {
|
||||
pattern: RegExp;
|
||||
@@ -60,7 +64,8 @@ async function GenericUpsert<T>(
|
||||
collection: ICollection<T>,
|
||||
field: keyof T,
|
||||
logger: KtLogger,
|
||||
remove = false
|
||||
remove = false,
|
||||
update = true
|
||||
) {
|
||||
logger.verbose(`Running bulkwrite.`);
|
||||
|
||||
@@ -89,7 +94,7 @@ async function GenericUpsert<T>(
|
||||
// @ts-expect-error Actually, T is assignable to OptionalId<T>.
|
||||
insertOne: { document },
|
||||
});
|
||||
} else if (fjsh.hash(document, "sha256") !== fjsh.hash(exists, "sha256")) {
|
||||
} else if (update && fjsh.hash(document, "sha256") !== fjsh.hash(exists, "sha256")) {
|
||||
bwriteOps.push({
|
||||
replaceOne: {
|
||||
// @ts-expect-error Known X->Y generic issue.
|
||||
@@ -243,6 +248,21 @@ const syncInstructions: SyncInstructions[] = [
|
||||
await GenericUpsert(bmsCourseDocuments, collection, "md5sums", logger);
|
||||
},
|
||||
},
|
||||
{
|
||||
pattern: /^goals/u,
|
||||
handler: async (goals: GoalDocument[], collection: ICollection<GoalDocument>, logger) => {
|
||||
// never remove goals. Never update goals either. Only insert new ones as
|
||||
// they come in.
|
||||
await GenericUpsert(
|
||||
goals.filter((e) => IsSupported(e.game)),
|
||||
collection,
|
||||
"goalID",
|
||||
logger,
|
||||
false,
|
||||
false
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const logger = CreateLogCtx("Database Sync");
|
||||
|
||||
Reference in New Issue
Block a user