-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #382 from cardano-foundation/feat/MET-2065-create-…
…job-to-count-token-tx feat: create job to count token tx and add index for address tx count…
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/main/java/org/cardanofoundation/job/repository/ledgersync/TokenTxCountRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.cardanofoundation.job.repository.ledgersync; | ||
|
||
import jakarta.transaction.Transactional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import org.cardanofoundation.explorer.common.entity.ledgersync.TokenTxCount; | ||
|
||
public interface TokenTxCountRepository extends JpaRepository<TokenTxCount, Long> { | ||
@Modifying(clearAutomatically = true) | ||
@Transactional | ||
@Query(value = "REFRESH MATERIALIZED VIEW token_tx_count", nativeQuery = true) | ||
void refreshMaterializedView(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 24 additions & 1 deletion
25
...esources/db/migration/ledgersync/V1_3_24__add_materialized_view_for_address_tx_count_.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
-- address_tx_count | ||
DROP MATERIALIZED VIEW IF EXISTS address_tx_count; | ||
|
||
CREATE MATERIALIZED VIEW address_tx_count AS | ||
SELECT add.address AS address, | ||
count(distinct ata.tx_hash) AS tx_count | ||
FROM address add | ||
left join address_tx_amount ata on ata.address = add.address | ||
GROUP BY add.address; | ||
GROUP BY add.address; | ||
|
||
CREATE INDEX IF NOT EXISTS address_tx_count_address_idx ON address_tx_count (address); | ||
CREATE INDEX IF NOT EXISTS address_tx_count_tx_count_idx ON address_tx_count (tx_count); | ||
|
||
-- token_tx_count | ||
DROP MATERIALIZED VIEW IF EXISTS token_tx_count; | ||
|
||
CREATE MATERIALIZED VIEW token_tx_count as | ||
SELECT ma.id as ident, count(distinct (ata.tx_hash)) as tx_count | ||
FROM address_tx_amount ata | ||
JOIN multi_asset ma ON ata.unit = ma.unit | ||
GROUP BY ma.id; | ||
|
||
CREATE INDEX IF NOT EXISTS token_tx_count_ident_idx ON token_tx_count(ident); | ||
CREATE INDEX IF NOT EXISTS token_tx_count_tx_count_idx ON token_tx_count(tx_count); | ||
|
||
-- add index for address entitys | ||
|
||
CREATE INDEX IF NOT EXISTS address_address_hash_idx ON address using hash (address); | ||
CREATE INDEX IF NOT EXISTS address_payment_credential_hash_idx ON address using hash (payment_credential); | ||
CREATE INDEX IF NOT EXISTS address_stake_address_hash_idx ON address using hash (stake_address); | ||
CREATE INDEX IF NOT EXISTS address_stake_credential_hash_idx ON address using hash (stake_credential); |