new register

This commit is contained in:
2025-10-22 11:28:53 +02:00
parent 60e64fa892
commit 91163b8a75
5 changed files with 627 additions and 81 deletions
+8 -16
View File
@@ -1,8 +1,7 @@
const admin = require("firebase-admin");
const { onSchedule } = require("firebase-functions/v2/scheduler");
const { logger } = require("firebase-functions/logger");
const db = admin.firestore();
const { refList } = require("../index");
const firestore = refList.projects.firestore;
function buildMonthContext(referenceDate) {
const current = referenceDate ? new Date(referenceDate) : new Date();
@@ -35,15 +34,10 @@ exports.snapshotMonthlyTopSongs = onSchedule(
async (event) => {
const { scheduleTime } = event;
const context = buildMonthContext(
scheduleTime ? new Date(scheduleTime) : new Date(),
scheduleTime ? new Date(scheduleTime) : new Date()
);
logger.info(
`[snapshotMonthlyTopSongs] Start ranking for ${context.monthKey}`,
);
const topProjectsSnap = await db
.collection("projects")
const topProjectsSnap = await refList.projects
.orderBy("views", "desc")
.limit(3)
.get();
@@ -62,7 +56,9 @@ exports.snapshotMonthlyTopSongs = onSchedule(
};
});
const docRef = db.collection("monthlyTopSongs").doc(context.monthKey);
const docRef = firestore
.collection("monthlyTopSongs")
.doc(context.monthKey);
const existingSnapshot = await docRef.get();
const payload = {
@@ -83,9 +79,5 @@ exports.snapshotMonthlyTopSongs = onSchedule(
}
await docRef.set(payload, { merge: true });
logger.info(
`[snapshotMonthlyTopSongs] Stored ${topProjects.length} projects for ${context.monthKey}`,
);
},
}
);