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: filter spaces by strategies, plugins and network #704

Closed
wants to merge 3 commits into from
Closed

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Oct 10, 2023

Fix #548
Fix #535

Add strategies_in and plugins_in filter to Space.

This allow query such as:

query Spaces {
  spaces(
    first: 10,
    where: { plugins_in: ["poap", "progress"], strategies_in: ["whitelist"], network: "1" }
  ) {
    strategies {
      name
    }
    plugins
    network
  }
}

Those filters behave differently than the proposal's strategies_contains.

strategies_contains is using string search, and can match anything, such as {.
strategies/plugins_in filter will exact match the strategy/plugin name.

Feature has been applied to Proposal via #705

The strategies search only apply to level 2 strategies, and will not match nested strategies

Creating the following indices will improve search performance

ALTER TABLE spaces
ADD INDEX strategies_idx ((CAST(JSON_EXTRACT(settings, "$.strategies[*].name") AS CHAR(255) ARRAY) )) USING BTREE;

ALTER TABLE spaces
ADD INDEX plugins_idx ((CAST(JSON_KEYS(settings, "$.plugins") AS CHAR(255) ARRAY) )) USING BTREE;

ALTER TABLE spaces
ADD INDEX network_idx ((CAST(JSON_UNQUOTE(JSON_EXTRACT(settings, "$.network")) AS CHAR(255)) COLLATE utf8mb4_bin )) USING BTREE;

The goal of those new filters will be to enable the snapshot UI to show the list of spaces using specific network/strategy/plugin

Note

JSON_OVERLAPS require Mysql version >= 8.0.17

@wa0x6e wa0x6e requested a review from ChaituVR October 10, 2023 04:50
@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

Attention: Patch coverage is 0% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/graphql/helpers.ts 0.00% 16 Missing ⚠️
Additional details and impacted files

📢 Thoughts on this report? Let us know!

@wa0x6e wa0x6e changed the title feat: filter spaces by strategies and plugins feat: filter spaces by strategies, plugins and network Oct 19, 2023
@@ -165,6 +165,21 @@ export async function fetchSpaces(args) {
orderDirection = orderDirection.toUpperCase();
if (!['ASC', 'DESC'].includes(orderDirection)) orderDirection = 'DESC';

if (where.strategies_in) {
queryStr += " AND JSON_OVERLAPS(JSON_EXTRACT(settings, '$.strategies[*].name'), JSON_ARRAY(?))";
Copy link
Member

Choose a reason for hiding this comment

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

It only returns spaces that return space that uses only one strategy, it should return any space that use the strategy being passed

For example if space A is using ticket and erc721 and space B is using just ticket strategy,
now if we request with strategies_in:["ticket"] it return only space B, it should return space A too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be the case already, that's the job of JSON_OVERLAPS. Do you have a specific example I can test ?

Running the query in the description is giving me spaces using multiple strategies

"strategies": [
          {
            "name": "whitelist"
          },
          {
            "name": "delegation"
          },
          {
            "name": "moloch-all"
          },
          {
            "name": "loot-character-guilds"
          },
          {
            "name": "rocketpool-node-operator"
          },
          {
            "name": "honeyswap"
          },
          {
            "name": "xdai-stake-holders"
          },
          {
            "name": "yearn-vault"
          }
        ],

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