Skip to content

Commit

Permalink
Remove short URLs that have never been accessed after 30 days
Browse files Browse the repository at this point in the history
  • Loading branch information
gruppler committed Aug 11, 2024
1 parent 9d7fba0 commit 3ada08b
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -120,7 +113,7 @@ exports.urlCleanup = functions.pubsub

async function deleteExpiredURL(doc) {
return db.collection("urls").doc(doc.id).delete();
} */
}

//#region PNG/GIF

Expand Down

0 comments on commit 3ada08b

Please sign in to comment.