Skip to content

Commit

Permalink
Merge pull request hirosystems#290 from hirosystems/beta
Browse files Browse the repository at this point in the history
release to master
  • Loading branch information
rafaelcr authored Jan 9, 2024
2 parents addda07 + f9bf829 commit 3ea22ca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [2.1.1-beta.2](https://github.com/hirosystems/ordinals-api/compare/v2.1.1-beta.1...v2.1.1-beta.2) (2024-01-09)


### Bug Fixes

* optimize BRC-20 activity count by ticker ([#289](https://github.com/hirosystems/ordinals-api/issues/289)) ([0a7648e](https://github.com/hirosystems/ordinals-api/commit/0a7648ee899e5167a72422c1c0870accad4c2423))

## [2.1.1-beta.1](https://github.com/hirosystems/ordinals-api/compare/v2.1.0...v2.1.1-beta.1) (2024-01-05)


### Bug Fixes

* remove problematic migration ([a82d078](https://github.com/hirosystems/ordinals-api/commit/a82d078fa9c30dddf15ec79746599c6dd527b7f1))

## [2.1.0](https://github.com/hirosystems/ordinals-api/compare/v2.0.1...v2.1.0) (2024-01-04)


Expand Down
2 changes: 0 additions & 2 deletions migrations/1704341578275_jubilee-numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export function up(pgm: MigrationBuilder): void {
type: 'bigint',
},
});
pgm.sql(`UPDATE inscriptions SET classic_number = number`);
pgm.alterColumn('inscriptions', 'classic_number', { notNull: true });
}

export function down(pgm: MigrationBuilder): void {
Expand Down
21 changes: 17 additions & 4 deletions src/pg/brc20/brc20-pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,17 @@ export class Brc20PgStore extends BasePgStoreModule {
objRemoveUndefinedValues(filters);
const filterLength = Object.keys(filters).length;
// Do we need a specific result count such as total activity or activity per address?
const needsGlobalEventCount = filterLength === 0 || (filterLength === 1 && filters.operation);
const needsGlobalEventCount =
filterLength === 0 ||
(filterLength === 1 && filters.operation && filters.operation.length > 0);
const needsAddressEventCount =
(filterLength === 1 && filters.address) ||
(filterLength === 2 && filters.operation && filters.address);
(filterLength === 1 && filters.address != undefined && filters.address != '') ||
(filterLength === 2 &&
filters.operation &&
filters.operation.length > 0 &&
filters.address != undefined &&
filters.address != '');
const needsTickerCount = filterLength === 1 && filters.ticker && filters.ticker.length > 0;
// Which operations do we need if we're filtering by address?
const sanitizedOperations: DbBrc20EventOperation[] = [];
for (const i of filters.operation ?? BRC20_OPERATIONS)
Expand Down Expand Up @@ -796,6 +803,12 @@ export class Brc20PgStore extends BasePgStoreModule {
FROM brc20_counts_by_address_event_type
WHERE address = ${filters.address}
`
: needsTickerCount
? this.sql`
SELECT COALESCE(SUM(tx_count), 0) AS count
FROM brc20_deploys AS d
WHERE (${tickerConditions})
`
: this.sql`SELECT NULL AS count`
})
SELECT
Expand All @@ -815,7 +828,7 @@ export class Brc20PgStore extends BasePgStoreModule {
(SELECT amount FROM brc20_mints WHERE id = e.mint_id) AS mint_amount,
(SELECT amount || ';' || from_address || ';' || COALESCE(to_address, '') FROM brc20_transfers WHERE id = e.transfer_id) AS transfer_data,
${
needsGlobalEventCount || needsAddressEventCount
needsGlobalEventCount || needsAddressEventCount || needsTickerCount
? this.sql`(SELECT count FROM event_count)`
: this.sql`COUNT(*) OVER()`
} AS total
Expand Down

0 comments on commit 3ea22ca

Please sign in to comment.