Repository navigation
fix(posts): sort by published date with grabbed date fallback - #182
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The queries, index, migration metadata, and regression coverage consistently implement the intended ordering.
0 open findings
What changed in this PR
Updates post ordering to use publication time with ingestion time as fallback.
Changes:
- Applies consistent deterministic ordering to bot, tag, and global listings.
- Adds a matching partial database index and migration.
- Adds regression coverage for fallback ordering, ties, pagination, and deleted entries.
| File | Description |
|---|---|
src/lib/schema.ts |
Defines the chronological composite index. |
src/lib/db.ts |
Shares the new ordering across listing queries. |
src/lib/__tests__/db.test.ts |
Tests ordering and pagination behavior. |
drizzle/0021_chronological_post_order.sql |
Rebuilds the index. |
drizzle/meta/0021_snapshot.json |
Records the updated schema snapshot. |
drizzle/meta/_journal.json |
Registers migration 0021. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
New posts are still being ingested, but PostgreSQL sorts null publication dates first, filling the first page with undated posts. Sort post, bot, and tag listings newest-first by
COALESCE(published_at, created_at), with an ID tie-breaker and a matching index.Verified: all 312 tests passed against disposable PostgreSQL, plus lint/typecheck, production build, and feed validation. Regression coverage checks fallback dates, publication-date precedence, pagination, and deleted posts.
Risks
The startup migration rebuilds the chronological index and can briefly block writes while it runs. Undated posts now appear according to when they were grabbed.