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

feat_: optimize endpoint calls when fetching balances #21802

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

briansztamfater
Copy link
Member

@briansztamfater briansztamfater commented Dec 11, 2024

may fix #21804

Summary

Not sure if related to this Android freeze, but when we load all accounts balances either on initial login or pull to refresh, we fetch prices and market values once per account. That may be lot of redundant data to process if the user has accounts with many tokens. This PR optimizes the corresponding re-frame events to fetch all balances for all accounts in the same endpoint call, and also fetches prices and market values once per refresh.

Platforms

  • Android
  • iOS

Areas that maybe impacted

Functional
  • wallet / transactions

Steps to test

  • Open Status
  • Log in with a user with many accounts
  • Verify initial wallet loading or pull to refresh is faster

status: ready

@status-im-auto
Copy link
Member

status-im-auto commented Dec 11, 2024

Jenkins Builds

Click to see older builds (4)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ f71268e #1 2024-12-11 17:45:13 ~4 min tests 📄log
✔️ f71268e #1 2024-12-11 17:48:25 ~7 min android-e2e 🤖apk 📲
✔️ f71268e #1 2024-12-11 17:48:52 ~8 min android 🤖apk 📲
✔️ f71268e #1 2024-12-11 17:53:52 ~13 min ios 📱ipa 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 30da907 #2 2024-12-11 23:13:08 ~4 min tests 📄log
✔️ 30da907 #2 2024-12-11 23:15:13 ~7 min android-e2e 🤖apk 📲
✔️ 30da907 #2 2024-12-11 23:15:26 ~7 min ios 📱ipa 📲
✔️ 30da907 #2 2024-12-11 23:16:22 ~8 min android 🤖apk 📲
✔️ 203d416 #3 2024-12-16 15:02:52 ~5 min tests 📄log
✔️ 203d416 #3 2024-12-16 15:04:27 ~6 min ios 📱ipa 📲
✔️ 203d416 #3 2024-12-16 15:06:50 ~9 min android-e2e 🤖apk 📲
✔️ 203d416 #3 2024-12-16 15:07:06 ~9 min android 🤖apk 📲

@briansztamfater briansztamfater force-pushed the fix/optimize-fetch-balance-calls branch from f71268e to 30da907 Compare December 11, 2024 23:07
Copy link
Contributor

@mohsen-ghafouri mohsen-ghafouri left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +207 to +210
(let [addresses (->> (get-in db [:wallet :accounts])
(vals)
(keep :address)
(vec))]
Copy link
Member

Choose a reason for hiding this comment

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

Since we index the accounts by address in app-db, we can skip going through it again.

Suggested change
(let [addresses (->> (get-in db [:wallet :accounts])
(vals)
(keep :address)
(vec))]
(let [addresses (-> (get-in db [:wallet :accounts])
(keys))]

:params [[address] true]
:on-success [:wallet/store-wallet-token address]
:on-error [:wallet/get-wallet-token-for-account-failed address]}]]]}))
:params [addresses true]
Copy link
Member

Choose a reason for hiding this comment

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

A suggestion for later: if the user tries to refresh within one minute or something, can we fetch only the cached balance during that time? This would reduce the load on status-go, and RPC requests as well. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good idea, maybe 1 minute is a lot of time depending on the situation (specially for L2s where transactions are faster), but let's define this with the design team and implement it on a separate issue.

@status-im-auto
Copy link
Member

62% of end-end tests have passed

Total executed tests: 8
Failed tests: 3
Expected to fail tests: 0
Passed tests: 5
IDs of failed tests: 727230,702745,727229 

Failed tests (3)

Click to expand
  • Rerun failed tests

  • Class TestWalletMultipleDevice:

    1. test_wallet_send_asset_from_drawer, id: 727230
    Test setup failed: critical/test_wallet.py:22: in prepare_devices
        self.drivers, self.loop = create_shared_drivers(2)
    base_test_case.py:310: in create_shared_drivers
        drivers = loop.run_until_complete(start_threads(test_suite_data.current_test.name,
    /usr/lib/python3.10/asyncio/base_events.py:649: in run_until_complete
        return future.result()
    __init__.py:26: in start_threads
        returns[k] = await returns[k]
    /usr/lib/python3.10/concurrent/futures/thread.py:58: in run
        result = self.fn(*self.args, **self.kwargs)
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/appium/webdriver/webdriver.py:257: in __init__
        super().__init__(
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py:206: in __init__
        self.start_session(capabilities)
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/appium/webdriver/webdriver.py:346: in start_session
        response = self.execute(RemoteCommand.NEW_SESSION, w3c_caps)
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py:345: in execute
        self.error_handler.check_response(response)
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py:229: in check_response
        raise exception_class(message, screen, stacktrace)
     Sauce could not start your job. For more information on what happened, please visit https://app.eu-central-1.saucelabs.com/tests/fa76e92716734f82b1223e5a194f3155
    



    2. test_wallet_send_eth, id: 727229

    Test setup failed: critical/test_wallet.py:22: in prepare_devices
        self.drivers, self.loop = create_shared_drivers(2)
    base_test_case.py:310: in create_shared_drivers
        drivers = loop.run_until_complete(start_threads(test_suite_data.current_test.name,
    /usr/lib/python3.10/asyncio/base_events.py:649: in run_until_complete
        return future.result()
    __init__.py:26: in start_threads
        returns[k] = await returns[k]
    /usr/lib/python3.10/concurrent/futures/thread.py:58: in run
        result = self.fn(*self.args, **self.kwargs)
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/appium/webdriver/webdriver.py:257: in __init__
        super().__init__(
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py:206: in __init__
        self.start_session(capabilities)
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/appium/webdriver/webdriver.py:346: in start_session
        response = self.execute(RemoteCommand.NEW_SESSION, w3c_caps)
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py:345: in execute
        self.error_handler.check_response(response)
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py:229: in check_response
        raise exception_class(message, screen, stacktrace)
     Sauce could not start your job. For more information on what happened, please visit https://app.eu-central-1.saucelabs.com/tests/fa76e92716734f82b1223e5a194f3155
    



    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745

    Test setup failed: critical/chats/test_1_1_public_chats.py:20: in prepare_devices
        self.drivers, self.loop = create_shared_drivers(2)
    base_test_case.py:310: in create_shared_drivers
        drivers = loop.run_until_complete(start_threads(test_suite_data.current_test.name,
    /usr/lib/python3.10/asyncio/base_events.py:649: in run_until_complete
        return future.result()
    __init__.py:26: in start_threads
        returns[k] = await returns[k]
    /usr/lib/python3.10/concurrent/futures/thread.py:58: in run
        result = self.fn(*self.args, **self.kwargs)
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/appium/webdriver/webdriver.py:257: in __init__
        super().__init__(
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py:206: in __init__
        self.start_session(capabilities)
    ../../../../status-app-prs@tmp/venv/lib/python3.10/site-packages/appium/webdriver/webdriver.py:360: in start_session
        raise SessionNotCreatedException(
     A valid W3C session creation response must contain a non-empty "sessionId" entry. Got "{'value': {'error': 'unknown error', 'message': 'failed serving request GET /wd/hub/session/3aa7d17d26a746578642c16a029cf282', 'stacktrace': ''}}" instead
    



    Passed tests (5)

    Click to expand

    Class TestCommunityOneDeviceMerged:

    1. test_community_copy_and_paste_message_in_chat_input, id: 702742
    Device sessions

    2. test_restore_multiaccount_with_waku_backup_remove_profile_switch, id: 703133
    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_message_edit, id: 702843
    Device sessions

    Class TestWalletOneDevice:

    1. test_wallet_add_remove_regular_account, id: 727231
    2. test_wallet_balance_mainnet, id: 740490

    @VolodLytvynenko VolodLytvynenko self-assigned this Dec 16, 2024
    @status-im-auto
    Copy link
    Member

    100% of end-end tests have passed

    Total executed tests: 3
    Failed tests: 0
    Expected to fail tests: 0
    Passed tests: 3
    

    Passed tests (3)

    Click to expand

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745
    Device sessions

    Class TestWalletMultipleDevice:

    1. test_wallet_send_asset_from_drawer, id: 727230
    2. test_wallet_send_eth, id: 727229

    @VolodLytvynenko
    Copy link
    Contributor

    hi @briansztamfater thank you for PR. No issues from my side. PR is ready to be merged

    @briansztamfater briansztamfater force-pushed the fix/optimize-fetch-balance-calls branch from 30da907 to 203d416 Compare December 16, 2024 14:57
    @briansztamfater briansztamfater merged commit 8d61580 into develop Dec 16, 2024
    5 checks passed
    @briansztamfater briansztamfater deleted the fix/optimize-fetch-balance-calls branch December 16, 2024 15:11
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    Status: DONE
    Development

    Successfully merging this pull request may close these issues.

    Sometimes wallet screen UI becomes unresponsive after pull to refresh
    7 participants