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

fix: get network data from DB directly #722

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Oct 18, 2023

🧿 Current issues / What's wrong ?

The network query on the hub is using data from space's cache.
This create refresh lag, and dependency on the space cache object.

💊 Fixes / Solution

Use a SQL query to get networks count data from the database, and return more network properties, allowing queries like:

query Networks {
  networks {
    key
    id
    spacesCount
    name
    chainId
    network
    explorer {
      url
      apiUrl
    }
    logo
    testnet
  }
}

🚧 Changes

  • Get networks count data from the database instead of space's cache
  • Return more fields from networks.json. Not all fields from networks.json are returned, only the one used by the snapshot UI.

🛠️ Tests

  • Query some network data from graphql => it should return same results as before, in addition to the new fields

@wa0x6e wa0x6e requested a review from ChaituVR October 18, 2023 10:47
@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Attention: 28 lines in your changes are missing coverage. Please review.

Comparison is base (cf26dfe) 2.41% compared to head (63099d7) 2.39%.

Additional details and impacted files
@@            Coverage Diff            @@
##           master    #722      +/-   ##
=========================================
- Coverage    2.41%   2.39%   -0.03%     
=========================================
  Files          39      39              
  Lines        2032    2050      +18     
  Branches       37      37              
=========================================
  Hits           49      49              
- Misses       1946    1964      +18     
  Partials       37      37              
Files Coverage Δ
src/graphql/operations/networks.ts 0.00% <0.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ChaituVR ChaituVR left a comment

Choose a reason for hiding this comment

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

But then we will miss new networks , where no one is using them yet

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Oct 18, 2023

But then we will miss new networks , where no one is using them yet

Aren’t they already missing from current implementation ?

@ChaituVR
Copy link
Member

Aren’t they already missing from current implementation ?

True lol. i thought we were using networks.json,

@ChaituVR
Copy link
Member

Would be nice if we could add it now 😄 so then maybe we can remove networks.json dependency on snapshot UI

Comment on lines 5 to 13
const query = `
SELECT
JSON_UNQUOTE(JSON_EXTRACT(settings, '$.network')) as network,
COUNT(name) AS spacesCount
FROM spaces
GROUP BY network
ORDER BY spacesCount DESC;
`;

Copy link
Member

Choose a reason for hiding this comment

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

Takes around 0.5 sec on prod, should be fine?

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Oct 19, 2023

Would be nice if we could add it now 😄 so then maybe we can remove networks.json dependency on snapshot UI

Added

@wa0x6e wa0x6e requested a review from ChaituVR October 19, 2023 02:54
@wa0x6e
Copy link
Contributor Author

wa0x6e commented Oct 19, 2023

Not all fields from networks.json are returned, tell me if we need to add more.

@wa0x6e wa0x6e added this to the Remove space cache milestone Oct 19, 2023
@wa0x6e
Copy link
Contributor Author

wa0x6e commented Nov 6, 2023

Pretty fast sql query, averaging 350ms execution time.

We could save the computation by caching the whole thing, and using SELECT MAX(updated) FROM spaces; as cache key

@wa0x6e wa0x6e marked this pull request as draft November 9, 2023 13:53
@wa0x6e
Copy link
Contributor Author

wa0x6e commented Nov 9, 2023

Need fix to also include networks from inside strategies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants