new register
This commit is contained in:
@@ -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}`,
|
||||
);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user