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

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

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: 145 lines in your changes are missing coverage. Please review.

Comparison is base (f41a7fa) 0.00% compared to head (85bb6b7) 0.00%.
Report is 12 commits behind head on master.

Additional details and impacted files
@@          Coverage Diff           @@
##           master    #704   +/-   ##
======================================
  Coverage    0.00%   0.00%           
======================================
  Files          40      40           
  Lines        1936    2013   +77     
  Branches       40      40           
======================================
- Misses       1896    1973   +77     
  Partials       40      40           
Files Coverage Δ
src/helpers/moderation.ts 0.00% <ø> (ø)
src/graphql/index.ts 0.00% <0.00%> (ø)
src/graphql/operations/follows.ts 0.00% <0.00%> (ø)
src/graphql/operations/proposal.ts 0.00% <0.00%> (ø)
src/graphql/operations/ranking.ts 0.00% <0.00%> (ø)
src/graphql/operations/subscriptions.ts 0.00% <0.00%> (ø)
src/graphql/operations/messages.ts 0.00% <0.00%> (ø)
src/graphql/operations/vote.ts 0.00% <0.00%> (ø)
src/graphql/operations/votes.ts 0.00% <0.00%> (ø)
src/helpers/spaces.ts 0.00% <0.00%> (ø)
... and 5 more

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

@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