mirror of https://github.com/flutter/pinball.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
819 B
29 lines
819 B
const functions = require("firebase-functions");
|
|
const admin = require("firebase-admin");
|
|
admin.initializeApp();
|
|
|
|
const db = admin.firestore();
|
|
|
|
exports.timedLeaderboardCleanup = functions.firestore
|
|
.document("leaderboard/{leaderboardEntry}")
|
|
.onCreate(async (_, __) => {
|
|
functions.logger.info(
|
|
"Document created, getting all leaderboard documents"
|
|
);
|
|
const snapshot = await db
|
|
.collection("leaderboard")
|
|
.orderBy("score", "desc")
|
|
.offset(10)
|
|
.get();
|
|
|
|
functions.logger.info(
|
|
`Preparing to delete ${snapshot.docs.length} documents.`
|
|
);
|
|
try {
|
|
await Promise.all(snapshot.docs.map((doc) => doc.ref.delete()));
|
|
functions.logger.info("Success");
|
|
} catch (error) {
|
|
functions.logger.error(`Failed to delete documents ${error}`);
|
|
}
|
|
});
|