Skip to content

feat: Feed sort tweaks#4143

Open
SylvainChevalier wants to merge 5 commits intomainfrom
claude/issue-4142-20260122-1453
Open

feat: Feed sort tweaks#4143
SylvainChevalier wants to merge 5 commits intomainfrom
claude/issue-4142-20260122-1453

Conversation

@SylvainChevalier
Copy link
Contributor

@SylvainChevalier SylvainChevalier commented Jan 22, 2026

Summary

Implements feed sort improvements requested in #4142:

  1. Add "Recently revealed" sort option to Home, My Predictions, My Questions & Posts, and Tournament feeds
  2. Rename "Recent Predictions" to "Recently predicted"
  3. In My Predictions feed: move "Divergence" to More menu and move "Withdrawing Soon" to quick sorts

Changes

  • Added CpRevealTimeDesc to QuestionOrder enum
  • Added "Recently revealed" to More menu in all specified feeds
  • Updated translation from "Recent predictions" to "Recently predicted"
  • Reordered My Predictions quick sorts and More menu options

Closes #4142


Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a "Recently revealed" sort option across question, prediction and tournament feeds; selecting it orders items by reveal time and shows only already-revealed items.
  • Updates

    • Renamed label "Recent predictions" → "Recently predicted" for consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add "Recently revealed" sort option to Home, My Predictions, My Questions & Posts, and Tournament feeds
- Rename "Recent Predictions" to "Recently predicted"
- In My Predictions feed: move "Divergence" to More menu and move "Withdrawing Soon" to quick sorts

Co-authored-by: Sylvain <SylvainChevalier@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds a "Recently revealed" sort (descending CP reveal time, only items with reveal time < now) across multiple feed filters, renames "Recent predictions" to "Recently predicted", and swaps "Divergence" and "Withdrawing Soon" positions in My Predictions sorts.

Changes

Cohort / File(s) Summary
Translations
front_end/messages/en.json
Added recentlyRevealed key and changed recentPredictions value to "Recently predicted".
Types
front_end/src/types/question.ts
Added CpRevealTimeDesc: "-cp_reveal_time" to QuestionOrder enum.
Frontend — Feed Filters
front_end/src/app/(main)/questions/components/feed_filters/main.tsx, front_end/src/app/(main)/questions/components/feed_filters/my_predictions.tsx, front_end/src/app/(main)/questions/components/feed_filters/my_questions_and_posts.tsx, front_end/src/components/tournament_filters.tsx
Introduced QuestionOrder.CpRevealTimeDesc labeled recentlyRevealed; swapped "Divergence" and "Withdrawing Soon" in My Predictions quick/sort menus.
Backend — Serializer & Feed Service
posts/serializers.py, posts/services/feed.py
Added CP_REVEAL_TIME = "cp_reveal_time" to filter Order; mapped it to question__cp_reveal_time ordering and added filter to include only posts with question__cp_reveal_time < now.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Frontend
  participant API
  participant Serializer
  participant FeedService
  participant Database

  Client->>Frontend: Select "Recently revealed" sort
  Frontend->>API: GET /posts?order=cp_reveal_time
  API->>Serializer: validate `order` param
  Serializer->>FeedService: pass Order.CP_REVEAL_TIME
  FeedService->>Database: query posts where question__cp_reveal_time < now ORDER BY question__cp_reveal_time DESC
  Database-->>FeedService: return ordered posts
  FeedService-->>API: posts payload
  API-->>Frontend: JSON response
  Frontend-->>Client: render sorted feed
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • lsabor

Poem

🐇 I hopped through keys and swapped a sort,
"Recently revealed" now leads the court,
Labels nudged and menus tidy,
Feeds reveal when clocks are ready,
I nibble code and cheer — carrot-party! 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title "Feed sort tweaks" is vague and doesn't clearly describe the specific changes made, such as adding reveal time sorting or renaming predictions. Consider a more descriptive title like "Add CP reveal time sort option and rename recent predictions" to better clarify the main changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR implements all three requirements from issue #4142: adds the CP reveal time sort option with proper filtering, renames the translation, and reorders My Predictions sorts.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #4142 requirements: translation updates, enum additions, and sort option implementations across multiple feed components.

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

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7511c30 and 909ef00.

📒 Files selected for processing (2)
  • front_end/messages/en.json
  • front_end/src/types/question.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • front_end/src/types/question.ts
  • front_end/messages/en.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build Docker Image / Build Docker Image
  • GitHub Check: integration-tests
  • GitHub Check: Frontend Checks
  • GitHub Check: Backend Checks

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@front_end/src/types/question.ts`:
- Line 53: The frontend added CpRevealTimeDesc (value "-cp_reveal_time") but the
backend PostFilterSerializer.Order enum is missing CP_REVEAL_TIME, so
validate_order_by will reject "-cp_reveal_time"; add CP_REVEAL_TIME =
"cp_reveal_time" to the PostFilterSerializer.Order enum (in
posts/serializers.py) so the Order enum includes this field and ordering by
cp_reveal_time/-cp_reveal_time is accepted by validate_order_by.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ad87c2 and acf00a3.

📒 Files selected for processing (6)
  • front_end/messages/en.json
  • front_end/src/app/(main)/questions/components/feed_filters/main.tsx
  • front_end/src/app/(main)/questions/components/feed_filters/my_predictions.tsx
  • front_end/src/app/(main)/questions/components/feed_filters/my_questions_and_posts.tsx
  • front_end/src/components/tournament_filters.tsx
  • front_end/src/types/question.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build Docker Image
  • GitHub Check: integration-tests
  • GitHub Check: Frontend Checks
  • GitHub Check: Backend Checks
🔇 Additional comments (6)
front_end/messages/en.json (1)

547-551: Copy update aligns with the new sort label.

Line 547 and Line 551 look good and match the new “Recently revealed” option plus the “Recently predicted” rename.

front_end/src/components/tournament_filters.tsx (1)

88-88: Nice addition to tournament sort options.

Line 88 cleanly wires the new “Recently revealed” sort to the enum and translation key.

front_end/src/app/(main)/questions/components/feed_filters/main.tsx (1)

143-143: Home feed “Recently revealed” option looks good.

Line 143 adds the new option in the More menu as requested.

front_end/src/app/(main)/questions/components/feed_filters/my_questions_and_posts.tsx (1)

94-94: Sort option added as expected.

Line 94 correctly adds “Recently revealed” to the More menu.

front_end/src/app/(main)/questions/components/feed_filters/my_predictions.tsx (2)

52-54: Quick-sort swap matches the requirement.

Lines 52–54 correctly surface “Withdrawing soon” as a quick sort.


70-75: More-menu updates look correct.

Lines 70–75 move “Divergence” to the More menu and add “Recently revealed” as intended.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 22, 2026

🚀 Preview Environment

Your preview environment is ready!

Resource Details
🌐 Preview URL https://metaculus-pr-4143-claude-issue-4142-20260122-145-preview.mtcl.cc
📦 Docker Image ghcr.io/metaculus/metaculus:claude-issue-4142-20260122-1453-85cf4b9
🗄️ PostgreSQL NeonDB branch preview/pr-4143-claude-issue-4142-20260122-145
Redis Fly Redis mtc-redis-pr-4143-claude-issue-4142-20260122-145

Details

  • Commit: 85cf4b921927df58bd4f2d19cf38dfcbe9a63979
  • Branch: claude/issue-4142-20260122-1453
  • Fly App: metaculus-pr-4143-claude-issue-4142-20260122-145

ℹ️ Preview Environment Info

Isolation:

  • PostgreSQL and Redis are fully isolated from production
  • Each PR gets its own database branch and Redis instance
  • Changes pushed to this PR will trigger a new deployment

Limitations:

  • Background workers and cron jobs are not deployed in preview environments
  • If you need to test background jobs, use Heroku staging environments

Cleanup:

  • This preview will be automatically destroyed when the PR is closed

@SylvainChevalier SylvainChevalier marked this pull request as draft January 22, 2026 15:48
This enables backend support for the cp_reveal_time ordering field
used by the new 'Recently revealed' sort option in the frontend.

Co-authored-by: Sylvain <SylvainChevalier@users.noreply.github.com>
@SylvainChevalier
Copy link
Contributor Author

@claude I get "Unexpected Api Error".

@claude
Copy link

claude bot commented Jan 22, 2026

Claude finished @SylvainChevalier's task in 1m 18s —— View job


Fixed the API error ✓

  • Understand the issue
  • Check if cp_reveal_time field exists in the Post model
  • Review backend implementation
  • Identify root cause
  • Implement fix
  • Commit and push

Root Cause

The cp_reveal_time field exists on the Question model, not on the Post model. When ordering Posts by cp_reveal_time, the Django ORM query needs to use question__cp_reveal_time to access this field through the relationship. Without this, the query tried to order by a non-existent field on the Post model, causing the "Unexpected API Error".

Fix Applied

Added special handling in posts/services/feed.py:315-317 to translate the cp_reveal_time order field to question__cp_reveal_time before building the order_by clause. This follows the same pattern used elsewhere in the codebase where fields on related models need the double-underscore notation (e.g., question__cp_reveal_time__lt=now on line 347).

The "Recently revealed" sort option should now work correctly across all feeds!

Commit: 5b9dd4b


| Branch

The cp_reveal_time field exists on the Question model, not the Post model.
When ordering Posts by this field, we need to use question__cp_reveal_time
to access it through the relationship.

Co-authored-by: Sylvain <SylvainChevalier@users.noreply.github.com>
@SylvainChevalier
Copy link
Contributor Author

@claude It's missing the filter for cp reveal time < now.

@claude
Copy link

claude bot commented Jan 22, 2026

Claude finished @SylvainChevalier's task in 1m 7s —— View job


Added cp_reveal_time < now filter ✓

  • Understand current implementation
  • Find where time-based filters are applied
  • Add cp_reveal_time < now filter
  • Commit and push changes

Root Cause

The code in posts/services/feed.py:315-317 handled the CP_REVEAL_TIME ordering by mapping it to question__cp_reveal_time, but it didn't filter to only show posts where the community prediction has actually been revealed.

Fix Applied

Added a filter on line 319 in posts/services/feed.py to only include posts where question__cp_reveal_time__lt=now. This follows the same pattern as other time-based filters like SCHEDULED_RESOLVE_TIME (lines 295-300).

Now the "Recently revealed" sort option will correctly show only posts where the community prediction has been revealed (cp_reveal_time < now).

Commit: 7511c30


| Branch

When ordering by CP_REVEAL_TIME, only include posts where the community
prediction has actually been revealed (cp_reveal_time < now). This
follows the same pattern as other time-based filters.

Co-authored-by: Sylvain <SylvainChevalier@users.noreply.github.com>
@SylvainChevalier
Copy link
Contributor Author

Tested on preview env, lgtm.

@SylvainChevalier SylvainChevalier marked this pull request as ready for review January 23, 2026 09:58
@hlbmtc
Copy link
Contributor

hlbmtc commented Jan 23, 2026

@SylvainChevalier But it only counts single questions, should we do for groups as well?

@SylvainChevalier
Copy link
Contributor Author

SylvainChevalier commented Jan 23, 2026

@hlbmtc ideally all the question-level sorts and filters would:

  • sort all questions
  • replace with posts
  • deduplicate posts, keeping only the top one of duplicates

Oh wait, is this what #4036 does? Then this new sort should work the same, yes.

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.

Feed sort tweaks

2 participants