Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
balance_tracker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
balance_tracker
Commits
c83d8649
Commit
c83d8649
authored
2 months ago
by
Michal Zander
Browse files
Options
Downloads
Patches
Plain Diff
Cross join in balance calculations - 9% faster,
Remove hardcoded hf01 check
parent
872a3abe
No related branches found
No related tags found
2 merge requests
!168
Update return types: VEST balances should be returned as strings to address JSON limitations
,
!158
Cross join in balance calculations (5% faster on full sync)
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
db/process_balances.sql
+14
-25
14 additions, 25 deletions
db/process_balances.sql
with
14 additions
and
25 deletions
db/process_balances.sql
+
14
−
25
View file @
c83d8649
...
...
@@ -24,42 +24,31 @@ WITH balance_impacting_ops AS MATERIALIZED
FROM
hafd
.
operation_types
ot
WHERE
ot
.
name
IN
(
SELECT
*
FROM
hive
.
get_balance_impacting_operations
())
),
ops_in_range
AS
ops_in_range
AS
MATERIALIZED
(
SELECT
(
SELECT
av
.
id
FROM
accounts_view
av
WHERE
av
.
name
=
get_impacted_balances
.
account_name
)
AS
account_id
,
get_impacted_balances
.
asset_symbol_nai
AS
nai
,
get_impacted_balances
.
amount
AS
balance
,
ho
.
id
AS
source_op
,
ho
.
block_num
AS
source_op_block
,
ho
.
body_binary
FROM
operations_view
ho
--- APP specific view must be used, to correctly handle reversible part of the data.
WHERE
ho
.
op_type_id
=
ANY
(
SELECT
id
FROM
balance_impacting_ops
)
AND
ho
.
block_num
BETWEEN
_from
AND
_to
ORDER
BY
ho
.
block_num
,
ho
.
id
JOIN
hafd
.
applied_hardforks
ah
ON
ah
.
hardfork_num
=
1
CROSS
JOIN
hive
.
get_impacted_balances
(
ho
.
body_binary
,
ho
.
block_num
>
ah
.
block_num
)
AS
get_impacted_balances
WHERE
ho
.
op_type_id
IN
(
SELECT
id
FROM
balance_impacting_ops
)
AND
ho
.
block_num
BETWEEN
_from
AND
_to
),
-- convert balances depending on hardforks
get_impacted_bal
AS
(
SELECT
hive
.
get_impacted_balances
(
gib
.
body_binary
,
gib
.
source_op_block
>
905693
)
AS
get_impacted_balances
,
gib
.
source_op
,
gib
.
source_op_block
FROM
ops_in_range
gib
),
convert_parameters
AS
(
SELECT
(
SELECT
av
.
id
FROM
accounts_view
av
WHERE
av
.
name
=
(
gi
.
get_impacted_balances
).
account_name
)
AS
account_id
,
(
gi
.
get_impacted_balances
).
asset_symbol_nai
AS
nai
,
(
gi
.
get_impacted_balances
).
amount
AS
balance
,
gi
.
source_op
,
gi
.
source_op_block
FROM
get_impacted_bal
gi
),
-- prepare accounts that were impacted by the operations
group_by_account_nai
AS
(
SELECT
cp
.
account_id
,
cp
.
nai
FROM
convert_parameters
cp
FROM
ops_in_range
cp
GROUP
BY
cp
.
account_id
,
cp
.
nai
),
get_latest_balance
AS
(
...
...
@@ -82,7 +71,7 @@ union_latest_balance_with_impacted_balances AS (
cp
.
balance
,
cp
.
source_op
,
cp
.
source_op_block
FROM
convert_parameters
cp
FROM
ops_in_range
cp
UNION
ALL
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment