Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB query in REST api /accounts/{id} includes unnecessary entity stake condition #7237

Closed
xin-hedera opened this issue Nov 21, 2023 · 0 comments · Fixed by #7391
Closed

DB query in REST api /accounts/{id} includes unnecessary entity stake condition #7237

xin-hedera opened this issue Nov 21, 2023 · 0 comments · Fixed by #7391
Assignees
Labels
bug Type: Something isn't working good first issue Good for newcomers rest Area: REST API
Milestone

Comments

@xin-hedera
Copy link
Collaborator

xin-hedera commented Nov 21, 2023

Description

The query for account info in /accounts/{id} has a condition (es.id = $1 OR es.id IS NULL) in the where clause of the main query. It's unnecessary since the query has entity as e left join entity_stake as es on es.id = e.id and there is already e.id = $1.

2023-11-21T11:22:36.945-06:00 TRACE e23e9d02 getOneAccount entity query: with latest_token_balance as (select account_id, balance, token_id
                                     from token_account
                                     where associated is true)
 select e.alias,
e.auto_renew_period,
e.balance_timestamp,
e.created_timestamp,
e.decline_reward,
e.deleted,
e.ethereum_nonce,
e.evm_address,
e.expiration_timestamp,
e.id,
e.key,
e.max_automatic_token_associations,
e.memo,
e.receiver_sig_required,
e.staked_account_id,
e.staked_node_id,
e.stake_period_start,
e.type,
e.timestamp_range,
(case when es.pending_reward is null then 0
         when e.decline_reward is true or coalesce(e.staked_node_id, -1) = -1 then 0
         when e.stake_period_start >= es.end_stake_period then 0
         else es.pending_reward
    end) as pending_reward,
(select json_agg(jsonb_build_object('token_id', token_id, 'balance', balance)) ::jsonb
                        from (select token_id, balance
                              from latest_token_balance
                              where account_id = $1
                              order by token_id asc
        limit 1000) as account_token_balance) as token_balances,
e.balance as balance
                       from entity e
                                left join entity_stake es on es.id = e.id
                       where e.type in ('ACCOUNT', 'CONTRACT') and e.id = $1 and (es.id = $1 OR es.id IS NULL)
                       order by e.id asc  [556677]

Steps to reproduce

Remove entityStakeQuery completely from accounts.js and make sure all tests pass

Additional context

No response

Hedera network

other

Version

v0.93.0-SNAPSHOT

Operating system

None

@xin-hedera xin-hedera added bug Type: Something isn't working rest Area: REST API labels Nov 21, 2023
@steven-sheehy steven-sheehy added the good first issue Good for newcomers label Dec 1, 2023
@edwin-greene edwin-greene self-assigned this Dec 15, 2023
@edwin-greene edwin-greene modified the milestone: 0.95.0 Dec 15, 2023
@edwin-greene edwin-greene linked a pull request Dec 15, 2023 that will close this issue
2 tasks
@steven-sheehy steven-sheehy added this to the 0.95.0 milestone Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Something isn't working good first issue Good for newcomers rest Area: REST API
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants