From 3ada08bd8f49a74bd69610e2f471d246a47b375d Mon Sep 17 00:00:00 2001 From: Craig Laparo Date: Thu, 11 Jul 2024 16:20:21 -0500 Subject: [PATCH] Remove short URLs that have never been accessed after 30 days --- functions/index.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/functions/index.js b/functions/index.js index 8e34c8e5..0951a066 100644 --- a/functions/index.js +++ b/functions/index.js @@ -86,28 +86,21 @@ exports.short = functions.https.onRequest(async (request, response) => { return true; }); -/* // Delete expired shortened URLs +// Delete expired shortened URLs exports.urlCleanup = functions.pubsub .schedule("every day 00:00") .onRun(async () => { - const LIMIT = new Date(Date.now() - 5 * 365 * 864e5); + const LIMIT = new Date(Date.now() - 30 * 864e5); - // Last accessed over 5 years ago + // Never accessed, created over 30 days ago let expiredURLs = ( - await db.collection("urls").where("accessed", "<=", LIMIT).get() + await db + .collection("urls") + .where("accessed", "==", null) + .where("created", "<=", LIMIT) + .get() ).docs; - // Never accessed, created over 5 years ago - expiredURLs = expiredURLs.concat( - ( - await db - .collection("urls") - .where("accessed", "==", null) - .where("created", "<=", LIMIT) - .get() - ).docs - ); - // Filter out permanent URLs expiredURLs = expiredURLs.filter((doc) => !doc.data().isPermanent); @@ -120,7 +113,7 @@ exports.urlCleanup = functions.pubsub async function deleteExpiredURL(doc) { return db.collection("urls").doc(doc.id).delete(); -} */ +} //#region PNG/GIF