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 proposals by plugins and strategies #705

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

This PR introduces a more robust proposal filtering by strategy and plugin name.

New filter

The current existing plugins_contains and strategies_contains are just basic string search, and will return false result.

The new introduced strategies_in and plugins_in filter will searc the JSON field by key name and value, and will only return exact matches, allowing queries such as:

query Proposals {
  proposals(first: 10, where: {plugins_in: ["aragon"]}) {
    plugins
  }
}
query Proposals {
  proposals(first: 10, where: {strategies_in: ["erc721"]}) {
    strategies { name }
  }
}

For better performance, adding an index to the JSON objects is recommended:

ALTER TABLE proposals
ADD INDEX plugin_idx ((CAST(JSON_KEYS(plugins) AS CHAR(255) ARRAY) )) 
USING BTREE;

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

Fixing existing filter

The existing validation filter is using basic string search. It has been updated for a more robust search by JSON value.

query Proposals {
  proposals(first: 10, where: {validation: "any"}) {
    validation {
      name
    }
  }
}

Proposed index:

ALTER TABLE proposals
ADD INDEX validation_idx ((CAST(JSON_EXTRACT(validation, "$.name") AS CHAR(255)) COLLATE utf8mb4_bin )) USING BTREE;

@wa0x6e wa0x6e requested a review from ChaituVR October 10, 2023 23:55
@wa0x6e wa0x6e changed the title feat: allow filtering proposals by plugin and strategies feat: filter proposals by plugins and strategies Oct 10, 2023
@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

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

Comparison is base (cf26dfe) 2.41% compared to head (6f1c334) 2.39%.

Additional details and impacted files
@@            Coverage Diff            @@
##           master    #705      +/-   ##
=========================================
- Coverage    2.41%   2.39%   -0.02%     
=========================================
  Files          39      39              
  Lines        2032    2042      +10     
  Branches       37      37              
=========================================
  Hits           49      49              
- Misses       1946    1956      +10     
  Partials       37      37              
Files Coverage Δ
src/graphql/operations/proposals.ts 0.00% <0.00%> (ø)

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

@wa0x6e wa0x6e changed the title feat: filter proposals by plugins and strategies feat: filter proposals by plugins and strategies Oct 19, 2023
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.

Refer to #704 (comment)

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Oct 28, 2023

Refer to #704 (comment)

The following query

query Proposals {
  proposals(first: 10, where: {strategies_in: ["poap"]}) {
    strategies {
      name
    }
  }
}

Does return proposals that partial match:

{
  "data": {
    "proposals": [
      {
        "strategies": [
          {
            "name": "poap"
          },
          {
            "name": "whitelist"
          }
        ]
      },
      {
        "strategies": [
          {
            "name": "poap"
          },
          {
            "name": "whitelist"
          }
        ]
      },
      {
        "strategies": [
          {
            "name": "poap"
          },
          {
            "name": "ticket"
          }
        ]
      },
      {
        "strategies": [
          {
            "name": "erc20-balance-of"
          },
          {
            "name": "whitelist"
          },
          {
            "name": "poap"
          }
        ]
      },
      {
        "strategies": [
          {
            "name": "whitelist"
          },
          {
            "name": "erc20-balance-of"
          },
          {
            "name": "poap"
          }
        ]
      },
      {
        "strategies": [
          {
            "name": "whitelist"
          },
          {
            "name": "erc20-balance-of"
          },
          {
            "name": "poap"
          }
        ]
      },
      {
        "strategies": [
          {
            "name": "poap"
          },
          {
            "name": "whitelist"
          }
        ]
      },
      {
        "strategies": [
          {
            "name": "poap"
          },
          {
            "name": "whitelist"
          }
        ]
      },
      {
        "strategies": [
          {
            "name": "poap"
          }
        ]
      },
      {
        "strategies": [
          {
            "name": "poap"
          }
        ]
      }
    ]
  }
}

@wa0x6e wa0x6e requested a review from ChaituVR October 28, 2023 14:53
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.

None yet

2 participants