Skip to content

Commit

Permalink
fix mozilla#107: DELETE_UNVERIFIED_SUBSCRIBERS_TIMER and logic
Browse files Browse the repository at this point in the history
patch
  • Loading branch information
groovecoder committed Aug 27, 2018
1 parent 7c4045d commit 3f6d64f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .env-dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PORT=6060
COOKIE_SECRET=3895d33b5f9730f5eb2a2067fe0a690e298f55f5e382c032fd3656863412

DATABASE_URL="postgres://postgres@localhost:5432/blurts"
# How many seconds can unverified subscribers remain in the database
DELETE_UNVERIFIED_SUBSCRIBERS_TIMER=86400

SMTP_URL=""

Expand Down
1 change: 1 addition & 0 deletions app-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const kEnvironmentVariables = [
"HIBP_API_ROOT",
"HIBP_API_TOKEN",
"DATABASE_URL",
"DELETE_UNVERIFIED_SUBSCRIBERS_TIMER",
];

const AppConstants = { };
Expand Down
4 changes: 4 additions & 0 deletions db/DB.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const uuidv4 = require("uuid/v4");
const Knex = require("knex");

const AppConstants = require("../app-constants");
const HIBP = require("../hibp");
const getSha1 = require("../sha1-utils");

Expand Down Expand Up @@ -119,8 +120,11 @@ const DB = {
},

async deleteUnverifiedSubscribers() {
const expiredDateTime = new Date(Date.now() - AppConstants.DELETE_UNVERIFIED_SUBSCRIBERS_TIMER * 1000);
const expiredTimeStamp = expiredDateTime.toISOString();
await knex("subscribers")
.where("verified", false)
.andWhere("created_at", "<", expiredTimeStamp)
.del();
},

Expand Down
7 changes: 1 addition & 6 deletions scripts/delete-unverified-subscribers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
const DB = require("../db/DB");


async function deleteUnverifiedSubscribers() {
await DB.deleteUnverifiedSubscribers();
}


(async () => {
await deleteUnverifiedSubscribers();
await DB.deleteUnverifiedSubscribers();
process.exit();
})();

0 comments on commit 3f6d64f

Please sign in to comment.