From f623fe3694ab63aede14022fea53bcbd4f99c016 Mon Sep 17 00:00:00 2001 From: overtorment Date: Sat, 8 Apr 2023 09:36:23 +0100 Subject: [PATCH] ADD: purge push log history; purge ignored addresses subscriptions --- scripts/mass_send.js | 18 +++++++--------- src/controller/GroundController.ts | 34 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/scripts/mass_send.js b/scripts/mass_send.js index 0b664c6..de5dc53 100644 --- a/scripts/mass_send.js +++ b/scripts/mass_send.js @@ -1,17 +1,15 @@ -const fs = require('fs'); +const fs = require("fs"); -const text = fs.readFileSync('all_tokens_unique.csv', {encoding: 'utf8'}); +const text = fs.readFileSync("all_tokens_unique.csv", { encoding: "utf8" }); -const lines = text.split('\n'); +const lines = text.split("\n"); - - -console.log('INSERT INTO send_queue_2 VALUES '); +console.log("INSERT INTO send_queue_2 VALUES "); for (const line of lines.slice(50000, 60000)) { - const [token, os] = line.split('\t'); - const sql = `(null, '{"type":5,"token":"${token}","os":"${os}","text":"If you are using Lightning, please read our blog post. The service is sunsetting. Balances should be moved to another service"}', null), `; - console.log(sql); + const [token, os] = line.split("\t"); + const sql = `(null, '{"type":5,"token":"${token}","os":"${os}","text":"If you are using Lightning, please read our blog post. The service is sunsetting. Balances should be moved to another service"}', null), `; + console.log(sql); } -console.log(';'); +console.log(";"); diff --git a/src/controller/GroundController.ts b/src/controller/GroundController.ts index a636e4b..b1b6a67 100644 --- a/src/controller/GroundController.ts +++ b/src/controller/GroundController.ts @@ -57,12 +57,46 @@ const ADDRESS_IGNORE_LIST = [ "1CK6KHY6MHgYvmRQ4PAafKYDrg1ejbH1cE", "36XWTfSYJJz3WSNPZVZ3q3aa5eFuJHR9nu", "bc1qc8ee9860cdnkyej0ag5hf49pcx7uvz89lkwpr9", + "bc1q7ug4w4as2sefar89q057hnmxkakp58a25535ttlmurn6cncs8tms4e7gp2", + "3JodN7GmkHdPgKj9G7HCkn9NDLhrcWCjVN", + "bc1qujepl0k5n0ga2e86yskvxa6auehpf6dlf84dx0", + "bc1qg9lgqyukp2rup5x4frrz7hhw7988k5q26luakm", + "3JSdUu1ivm3rqMvuCTAdAj6Dc2hdVhHiEe", ]; let connection: DataSource; + +const pushLogPurge = () => { + console.log("purging PushLog..."); + let today = new Date(); + connection + .createQueryBuilder() + .delete() + .from(PushLog) + .where("created <= :currentDate", { currentDate: new Date(today.getTime() - 3 * 24 * 60 * 60 * 1000) }) + .execute() + .then(() => console.log("PushLog purged ok")) + .catch((error) => console.log("error purging PushLog:", error)); +}; + +const purgeIgnoredAddressesSubscriptions = () => { + console.log("Purging addresses subscriptions..."); + connection + .createQueryBuilder() + .delete() + .from(TokenToAddress) + .where("address IN (:...id)", { id: ADDRESS_IGNORE_LIST }) + .execute() + .then(() => console.log("Addresses subscriptions purged ok")) + .catch((error) => console.log("error purging addresses subscriptions:", error)); +}; + dataSource.initialize().then((c) => { console.log("db connected"); connection = c; + purgeIgnoredAddressesSubscriptions(); + pushLogPurge(); + setInterval(pushLogPurge, 3600 * 1000); }); export class GroundController {