Skip to content

Commit

Permalink
Fix archive
Browse files Browse the repository at this point in the history
  • Loading branch information
opcatdev committed Nov 4, 2024
1 parent 1ca9853 commit 25f59cd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
12 changes: 1 addition & 11 deletions packages/tracker/src/entities/txOutArchive.entity.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {
Column,
CreateDateColumn,
Entity,
Index,
PrimaryColumn,
} from 'typeorm';
import { Column, CreateDateColumn, Entity, PrimaryColumn } from 'typeorm';

@Entity('tx_out_archive')
@Index(['spendTxid', 'spendInputIndex'], { unique: true })
@Index(['xOnlyPubKey', 'ownerPubKeyHash'])
export class TxOutArchiveEntity {
@PrimaryColumn({ length: 64 })
txid: string;
Expand All @@ -17,7 +9,6 @@ export class TxOutArchiveEntity {
outputIndex: number;

@Column({ name: 'block_height' })
@Index()
blockHeight: number;

@Column({ type: 'bigint' })
Expand All @@ -30,7 +21,6 @@ export class TxOutArchiveEntity {
xOnlyPubKey: string;

@Column({ name: 'owner_pkh', nullable: true })
@Index()
ownerPubKeyHash: string;

@Column({ name: 'token_amount', type: 'bigint', nullable: true })
Expand Down
35 changes: 35 additions & 0 deletions packages/tracker/src/migrations/1730693484057-alter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class Alter1730693484057 implements MigrationInterface {
name = 'Alter1730693484057';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX "public"."IDX_64dc10ae35b0b320fe29fe37c5"`,
);
await queryRunner.query(
`DROP INDEX "public"."IDX_41eccc4d16ad59f7d60e3ffffd"`,
);
await queryRunner.query(
`DROP INDEX "public"."IDX_7c34e770bfd147b45f053ae328"`,
);
await queryRunner.query(
`DROP INDEX "public"."IDX_016aa4b4d86115beff7679b908"`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_016aa4b4d86115beff7679b908" ON "tx_out_archive" ("spend_txid", "spend_input_index") `,
);
await queryRunner.query(
`CREATE INDEX "IDX_7c34e770bfd147b45f053ae328" ON "tx_out_archive" ("xonly_pubkey", "owner_pkh") `,
);
await queryRunner.query(
`CREATE INDEX "IDX_41eccc4d16ad59f7d60e3ffffd" ON "tx_out_archive" ("owner_pkh") `,
);
await queryRunner.query(
`CREATE INDEX "IDX_64dc10ae35b0b320fe29fe37c5" ON "tx_out_archive" ("block_height") `,
);
}
}
6 changes: 2 additions & 4 deletions packages/tracker/src/services/tx/tx.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,11 +927,9 @@ export class TxService {
.innerJoin('tx', 'tx', 'txOut.spend_txid = tx.txid')
.where('txOut.spend_txid IS NOT NULL')
.andWhere('tx.block_height < :blockHeight', {
blockHeight: lastProcessedHeight - 3 * 2880, // blocks before three days ago
blockHeight: lastProcessedHeight - 2880, // blocks before one day ago
})
.orderBy('tx.block_height', 'ASC')
.addOrderBy('tx.tx_index', 'ASC')
.limit(1000) // archive no more than 1000 records once a time
.limit(2500) // archive no more than 2500 records once a time
.getMany();
if (txOuts.length === 0) {
return;
Expand Down

0 comments on commit 25f59cd

Please sign in to comment.