Skip to content

Conversation

@hlbmtc
Copy link
Contributor

@hlbmtc hlbmtc commented Jan 9, 2026

Added a direct Question.post FK to replace the old QuestionPost database view. This simplifies queries and improves performance.

Changes:

  • New Question.post FK with related_name="questions"
  • Removed QuestionPost model entirely
  • Post.save() auto-syncs question FKs on creation
  • Replaced all related_questions__question__X lookups with questions__X
  • Replaced all related_posts lookups with posts
  • Optimized batch jobs (job_compute_movement, hotness, indexes) to use direct questions relation instead of prefetch_questions() when we don't need group/conditional structure

Queries are simpler, no more view indirection, and batch jobs skip loading unnecessary models.

closes #4031

Copy link
Contributor

@lsabor lsabor left a comment

Choose a reason for hiding this comment

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

This is a good change in my opinion. Code is fine and relatively simple.

Running the site locally works with no glitches. I checked the most important things such as browsing questions and notebooks, forecasting, resolving, leaderboard updating. I didn't check the more nuanced features like notifications and indexes, though I suspect they still work as expected.

Not that it's critical, but rolling back the migrations also worked properly.

I didn't benchmark anything to actually evaluate efficiencies, but nothing worked slower to the point where I could notice during normal use of the site.

Copy link
Contributor

@elisescu elisescu left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Move QuestionPost View to Question.post relation

4 participants