Skip to content

Reduce FeedbackById query cost via server-side aggregates #101

Description

@coopbri

Context

The FeedbackById query (app Feedback fragment) costs ~5295 under GraphQL Armor. The limit was raised 1200 → 6000 (omnidotdev/infra#48) to stop prod rejections, and the dashboard feed was trimmed (omnidotdev/backfeed-app#200). FeedbackById is the remaining heavy read.

Why it's heavy

The Feedback fragment fans out into six nested connections on a single post, all rendered on the detail page:

  • attachments
  • comments(parentId: null) totalCount + commentsWithReplies totalCount
  • upvotes / downvotes totalCount
  • userUpvotes / userDownvotes nodes
  • postTags

The four separate votes connections are the biggest contributor.

Proposed fix (server-side)

Add computed aggregate fields to the Post type via makeExtendSchemaPlugin so the client fetches one cheap field instead of 4–6 connections, e.g.:

  • voteSummary: { upvotes: Int!, downvotes: Int!, viewerVote: VoteType }
  • commentCounts: { topLevel: Int!, total: Int! }

Then update the app Feedback fragment to consume these, dropping the nested connections. This lets the cost limit be tightened back toward the peer range (400–1000).

Acceptance

  • FeedbackById cost well under the limit (target < 1000).
  • Detail page renders identically (vote counts, viewer's vote state, comment counts, tags, attachments).
  • Limit in infra/apps/backfeed/k8s.ts revisited downward once landed.

Not urgent (the 6000 limit covers current cost); this is the long-term cleanup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions