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

Controllers Improvements #2391

Merged
merged 4 commits into from
Jul 23, 2019
Merged

Controllers Improvements #2391

merged 4 commits into from
Jul 23, 2019

Conversation

pasqu4le
Copy link
Contributor

Motivation

after #2111, #2249, #2216 and #2305 a few remaining controllers still have not been checked for possible improvements.

This PR is the result of going trough all these controllers.

Changelog

There are 3 separate commits:

  1. Removes unnecessary preloads and queries
  2. Modifies Explorer.Chain functions to only take an hash/id where possible, just like it was done for Addresses
  3. Adds new functions to Exploerer.Chain to only check for the existence of an entity

Checklist for your PR

  • I added an entry to CHANGELOG.md with this PR
  • If I added new functionality, I added tests covering it.
  • If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
  • I checked whether I should update the docs and did so if necessary

@pasqu4le pasqu4le self-assigned this Jul 19, 2019
@pasqu4le pasqu4le force-pushed the pp-improve-controllers branch from 63b3e4b to cb0a06d Compare July 19, 2019 15:48
@coveralls
Copy link

coveralls commented Jul 19, 2019

Pull Request Test Coverage Report for Build 99ac9c93-55e6-480d-a66e-101d03c86a7a

  • 51 of 66 (77.27%) changed or added relevant lines in 17 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.002%) to 80.928%

Changes Missing Coverage Covered Lines Changed/Added Lines %
apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex 0 1 0.0%
apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex 0 4 0.0%
apps/explorer/lib/explorer/chain.ex 9 19 47.37%
Files with Coverage Reduction New Missed Lines %
apps/explorer/lib/explorer/chain.ex 1 79.61%
apps/block_scout_web/lib/block_scout_web/controllers/api/v1/verified_smart_contract_controller.ex 1 56.25%
Totals Coverage Status
Change from base Build e8dae500-635c-4255-b6c3-0243d5e67b8e: -0.002%
Covered Lines: 5215
Relevant Lines: 6444

💛 - Coveralls

pasqu4le added 4 commits July 19, 2019 17:59
Problem: after #2111, #2249, #2216 and #2305 a few remaining controllers still have not been checked for possible improvements.

Solution: check them and remove unnecessary preloads and queries.
Problem: a lot of function take an entity as an parameter, but only use its hash/id.
This makes tracing the necessary scope of functions harder and is one of the cause for unnecessary queries/code execution.

Solution: refactor these functions to take only a hash (or an id).
Problem: some controller retrieves entire entities from the database when it only needs to check their existence.

Solution: provide Exploerer.Chain functions to check for existence and use them where possible.
@pasqu4le pasqu4le force-pushed the pp-improve-controllers branch from cb0a06d to 4a46e6e Compare July 19, 2019 15:59
@pasqu4le pasqu4le added ready for review This PR is ready for reviews. and removed in progress labels Jul 19, 2019
Copy link
Contributor

@saneery saneery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I have a little question

@spec query_verified_contract(Hash.Address.t(), functions()) :: functions_results()
def query_verified_contract(address_hash, functions) do
@spec query_verified_contract(Hash.Address.t(), functions(), SmartContract.abi() | nil) :: functions_results()
def query_verified_contract(address_hash, functions, mabi \\ nil) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does mabi mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I gave it that name for maybe abi (because it can be nil) so that a few lines down the code is abi = ...

Copy link
Member

@vbaranov vbaranov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pasqu4le could you guide me which pages are mainly affected by this update to put my eyes on them from the performance point of view?

@pasqu4le
Copy link
Contributor Author

@vbaranov sure.

The first commit should have the biggest impact among the 3, pages affected are:

  • /smart_contracts/<address_hash> (also the ajax request)
  • /api?module=block&action=getblockreward&blockno=<number>

The second commit does not directly affect performances, but was necessary for the following one.

The third commit has a smaller impact, on these pages:

  • /address/<address_hash>/coin_balances
  • /address/<address_hash>/logs
  • /search_logs
  • /api/v1/decompiled_smart_contract
  • /api/v1/verified_smart_contracts
  • /smart_contracts/<address_hash> (ajax requests only)
  • /tx/<transaction_hash> (just the redirection)
  • /tx/<transaction_hash>/internal_transactions
  • /tx/<transaction_hash>/token_transfers

vbaranov added a commit that referenced this pull request Jul 23, 2019
@vbaranov vbaranov merged commit c716f42 into master Jul 23, 2019
@vbaranov vbaranov deleted the pp-improve-controllers branch July 23, 2019 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review This PR is ready for reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants