Skip to content

Commit 4790271

Browse files
committed
Database Cleanup System Overall Done
Within these final tweaks, we are now able not only to purge user records if confirmed_email is set to false, but to also check if they are inactiv during the last month. I created a check that will make sure that we wont delete the user just if the confirmed_email is set to false and also the createAt attribute refer to a date before one month ago. All of that by adding a simple if statement, the simpler the better ( @supernova350 ) Please refer to me if something is wrong. Thanks. Massiles.
1 parent 5c8cc8f commit 4790271

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/background_jobs/unconfirmed_emails.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
module.exports.remove_unconfirmed_email_users = async () => {
16-
console.log("job executed !")
1716

1817

1918
// find and retreive all the users with an unconfirmed email address
@@ -25,22 +24,23 @@ module.exports.remove_unconfirmed_email_users = async () => {
2524
{
2625
confirmed_email: false,
2726
},
28-
attributes: ['id'],
27+
attributes: ['id', 'createdAt'],
2928
raw: true,
3029
},
3130
)
32-
31+
3332
if (found_users != undefined && found_users.length) {
3433

35-
// at this stage found_users will look like [{id:1}, {id:2}]
36-
// we want to turn it into an ids array which will look like [1,2]
34+
// at this stage found_users will look like [ { id: 1, createdAt: '2022-03-26 22:23:43.002 +00:00' } ]
35+
// we want to turn it into an ids array which will look like [1], if the createdAt refers to a date before a month ago
3736
const ids = [];
3837
found_users.forEach((element) => {
39-
ids.push(element.id)
38+
if (Date.parse(element.createdAt) < (Date.now() - 30 * 24 * 60 * 60 * 1000)) {
39+
ids.push(element.id);
40+
}
4041
})
4142

4243

43-
4444
//remove all the data that belongs to a user with an unconfirmed email address
4545
await Promise.allSettled([
4646
Events.findAll(

0 commit comments

Comments
 (0)