Skip to content

#108 — Uses on Serialized JSON: Wrong Matches and Slow Queries #889

Description

@Topmatrixmor2014

Labels: Official Campaign | FWC26 GrantFox OSS Maybe Rewarded backend indexer performance bug

This is a backend issue for the GrantFox FWC26 campaign. Index event participants as columns and query them directly instead of scanning serialized JSON text.

Requirements and Context

backend/src/services/eventIndexer.jsqueryEventsByType (and queryEventsByPublicKey, getEventStats):

let where = `payload::text ILIKE $1 AND event_type = $2`;
const params = [`%${publicKey}%`, eventType];
  • payload::text ILIKE '%GABC…%' is a full-text substring scan over the entire contract_events table. The table already stores from_addr and to_addr columns, but they are only populated on insert and never used for queries.
  • ILIKE '%<publicKey>%' can match unrelated text: the public key GAAAA… (55 chars) appears inside other fields (e.g. a memo containing the string, or a nested payload array), producing wrong results — a user can see events they were not part of, and events are missed if the key appears in a field the query wasn't meant to match.
  • getEventStats has the same payload::text ILIKE scan, grouping on event_type — the most common dashboard query, and it's a full table scan on every call.

Objectives

  1. Rewrite queries to use from_addr = $1 OR to_addr = $2 (exact match) with an index on those columns (add a knex migration if missing).
  2. Keep payload matching only as an explicit opt-in (e.g. a search query param), and bound it.
  3. Add tests: exact-participant filtering returns only the user's events; a public key string appearing in a memo does not match.

Suggested Execution

  1. Fork and branch: git checkout -b fix/indexer-column-queries.
  2. Patch eventIndexer.js query helpers; add a migration for the index.
  3. Add tests; run npm run lint && npm test in backend/.

Acceptance Criteria

  • Participant queries use indexed exact-match columns, not ILIKE on JSON.
  • A memo containing a public key no longer produces false matches.
  • ≥4 tests; npm run lint clean.

Guidelines

  • Keep the in-memory fallback store in sync (it can keep the substring filter, documented as best-effort).

Timeframe: 48 hours

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26Third CampaignCampaign: Third CampaignbackendExpress backend issuesbugSomething isn't workingindexerindexerperformancePerformance improvements

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions