Skip to content

Add OrderFill token lookup index#13

Open
Surfict wants to merge 1 commit into
enviodev:mainfrom
Surfict:fix/orderfill-tokenid-index
Open

Add OrderFill token lookup index#13
Surfict wants to merge 1 commit into
enviodev:mainfrom
Surfict:fix/orderfill-tokenid-index

Conversation

@Surfict

@Surfict Surfict commented May 28, 2026

Copy link
Copy Markdown

Summary

  • Add a composite OrderFill index on tokenId, timestamp, and id. Without it, queries like this can require a sequential scan and sort on large OrderFill tables:
OrderFill(
  where: { tokenId: { _eq: $tokenId } }
  order_by: [{ timestamp: asc }, { id: asc }]
  limit: $first
)

This PR adds the V2 equivalent of the V1 token lookup index, adapted to the V2 schema.

Summary by CodeRabbit

  • Performance

    • Improved query performance through optimized database indexing.
  • Infrastructure

    • Updated schema formatting and structure for consistency.

Review Change Stack

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The OrderFill schema type in schema.graphql is updated to add a composite index on tokenId, timestamp, and id fields via an @index directive. The @storage directive is simultaneously reformatted from inline to a standalone directive block.

Changes

OrderFill Schema Indexing

Layer / File(s) Summary
OrderFill indexing directives
schema.graphql
The OrderFill type adds a @index directive with composite index on tokenId, timestamp, and id fields. The @storage(postgres: true, clickhouse: true) directive is reformatted as a standalone directive block.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add OrderFill token lookup index' accurately describes the primary change: adding an index directive to the OrderFill type for token lookups.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@schema.graphql`:
- Around line 24-26: The composite `@index` declaration on type OrderFill uses
fields: ["tokenId", "timestamp", "id"]—verify this matches Envio HyperIndex's
required type-level composite index syntax for composite indexes and adjust the
fields/order or annotation format if needed; after updating schema.graphql, run
pnpm codegen to regenerate TypeScript types and other generated artifacts so
OrderFill and its index are kept in sync with the schema.
- Around line 24-26: The GraphQL type OrderFill was changed in schema.graphql
but generated TypeScript types are stale; run the code generator to update
derived types. Execute the project codegen command (pnpm codegen) to regenerate
the TypeScript definitions that reference OrderFill so consumers (generated
types/usages) stay in sync with schema.graphql.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a9d47ce3-cc19-4276-b23c-9c23aa414272

📥 Commits

Reviewing files that changed from the base of the PR and between b8214db and 389b385.

📒 Files selected for processing (1)
  • schema.graphql

Comment thread schema.graphql
Comment on lines +24 to +26
type OrderFill
@index(fields: ["tokenId", "timestamp", "id"])
@storage(postgres: true, clickhouse: true) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Envio HyperIndex @index directive syntax documentation

💡 Result:

In Envio HyperIndex, the @index directive is used in your GraphQL schema to tell HyperIndex to create database indices for fields (and optionally composite indices) to improve query performance. Syntax (individual field index): type Transaction { userAddress: String! @index } Syntax (composite / multi-field index): // You put @index on a type and specify fields=[...] // Example from the docs: type Transfer @index(fields: ["from", "to", "tokenId"]) { from: String! @index to: String! @index tokenId: BigInt!... } Key behavior notes from the docs: - HyperIndex supports “the simplest form of indexing” by marking individual fields with @index.[1] - For “frequently query using multiple fields together”, HyperIndex recommends “composite indices” via the type-level form @index(fields: [...]).[1] - HyperIndex also creates indices automatically for all ID fields and for fields marked with @derivedFrom.[1] - The most common cause of slow queries is missing indices; if you filter or sort by a field without @index, add it.[1] If you share the exact schema snippet you’re trying to optimize (or which query is slow), I can suggest the minimal set of @index / composite @index(fields:...) directives to match your query patterns.

Citations:


Ensure composite @index is valid + regenerate after schema change

  • schema.graphql: @index(fields: ["tokenId", "timestamp", "id"]) on type OrderFill matches Envio HyperIndex’s documented type-level composite index syntax.
  • Run pnpm codegen after this schema.graphql change so generated types stay in sync.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@schema.graphql` around lines 24 - 26, The composite `@index` declaration on
type OrderFill uses fields: ["tokenId", "timestamp", "id"]—verify this matches
Envio HyperIndex's required type-level composite index syntax for composite
indexes and adjust the fields/order or annotation format if needed; after
updating schema.graphql, run pnpm codegen to regenerate TypeScript types and
other generated artifacts so OrderFill and its index are kept in sync with the
schema.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check if there are uncommitted codegen artifacts that suggest codegen was not run

# Check git status for generated files (common patterns for codegen output)
git status --short | rg -i 'generated|codegen|\.gen\.|types.*\.ts'

Repository: enviodev/polymarket-v2-indexer

Length of output: 56


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Check full working tree status (not just filtered patterns)
echo "=== git status --short ==="
git status --short

# 2) Inspect schema.graphql around the referenced lines
echo
echo "=== schema.graphql (lines 1-80) ==="
nl -ba schema.graphql | sed -n '1,80p'

Repository: enviodev/polymarket-v2-indexer

Length of output: 200


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== git status --short (porcelain) ==="
git status --short --porcelain=v1 || true

echo
echo "=== git status for schema.graphql ==="
git status --short --porcelain=v1 -- schema.graphql || true

echo
echo "=== schema.graphql lines 20-35 ==="
awk 'NR>=20 && NR<=35 { printf "%d:%s\n", NR, $0 }' schema.graphql

echo
echo "=== locate pnpm codegen script ==="
ls -la package.json pnpm-workspace.yaml pnpm-lock.yaml 2>/dev/null || true
rg -n '"codegen"' package.json pnpm-workspace.yaml 2>/dev/null || true
rg -n 'codegen' package.json pnpm-workspace.yaml 2>/dev/null || true

Repository: enviodev/polymarket-v2-indexer

Length of output: 985


Run pnpm codegen after this schema.graphql change (type OrderFill).
Generated types are derived from schema.graphql, so regenerating avoids stale code.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@schema.graphql` around lines 24 - 26, The GraphQL type OrderFill was changed
in schema.graphql but generated TypeScript types are stale; run the code
generator to update derived types. Execute the project codegen command (pnpm
codegen) to regenerate the TypeScript definitions that reference OrderFill so
consumers (generated types/usages) stay in sync with schema.graphql.

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.

1 participant