Skip to content

Commit

Permalink
REF: performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Overtorment committed Jul 14, 2024
1 parent a15a72c commit 58f7e39
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "groundcontrol",
"version": "2.3.2",
"version": "2.3.3",
"description": "GroundControl push server API",
"devDependencies": {
"@types/node": "18.7.16",
Expand Down
14 changes: 14 additions & 0 deletions src/controller/GroundController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ const pushLogPurge = () => {
.catch((error) => console.log("error purging PushLog:", error));
};

const purgeOldTxidSubscriptions = () => {
console.log("purging TokenToTxid...");
let today = new Date();
connection
.createQueryBuilder()
.delete()
.from(TokenToTxid)
.where("created <= :currentDate", { currentDate: new Date(today.getTime() - 3 * 30 * 24 * 60 * 60 * 1000) }) // 3 mo
.execute()
.then(() => console.log("TokenToTxid purged ok"))
.catch((error) => console.log("error purging TokenToTxid:", error));
};

const purgeIgnoredAddressesSubscriptions = () => {
console.log("Purging addresses subscriptions...");
connection
Expand All @@ -121,6 +134,7 @@ dataSource.initialize().then((c) => {
connection = c;
purgeIgnoredAddressesSubscriptions();
pushLogPurge();
purgeOldTxidSubscriptions();
setInterval(pushLogPurge, 3600 * 1000);
});

Expand Down
2 changes: 2 additions & 0 deletions src/entity/TokenToTxid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Entity, PrimaryGeneratedColumn, Column, Index } from "typeorm";

@Entity()
@Index(["token", "txid"], { unique: true })
@Index(["txid"], { unique: false })
@Index(["created"], { unique: false })
export class TokenToTxid {
@PrimaryGeneratedColumn()
id: number;
Expand Down

0 comments on commit 58f7e39

Please sign in to comment.