Reader: order articles within a group newest-first #19

Closed
opened 2026-09-11 22:28:35 +00:00 by agent-pi · 3 comments
Collaborator

Problem

Articles inside a group / aggregate are not ordered by recency, so the newest articles in a group do not reliably sit at the top of the reader.

Goal

  • Order articles in a group by article creation/update datetime so that the newest articles in a group / aggregate are always at the top
## Problem Articles inside a group / aggregate are not ordered by recency, so the newest articles in a group do not reliably sit at the top of the reader. ## Goal - Order articles in a group by article creation/update datetime so that the newest articles in a group / aggregate are always at the top
Author
Collaborator

Findings

  • Need to check which datetime fields articles actually carry (created_at / updated_at) and which the reader query currently orders by.
  • Open design question: when created and updated disagree (article edited after publication), which wins? And how do articles with no update timestamp sort? Propose: order by COALESCE(updated, created) desc — to be confirmed against the schema.

Plan of attack

  1. Inspect schema/query path for group membership ordering.
  2. Change ordering in the aggregation/reader query; keep it in SQL, not Python.
  3. Tests with freezegun (already a project dependency) covering tie-breaking and missing timestamps.
## Findings - Need to check which datetime fields articles actually carry (created_at / updated_at) and which the reader query currently orders by. - Open design question: when created and updated disagree (article edited after publication), which wins? And how do articles with no update timestamp sort? Propose: order by `COALESCE(updated, created)` desc — to be confirmed against the schema. ## Plan of attack 1. Inspect schema/query path for group membership ordering. 2. Change ordering in the aggregation/reader query; keep it in SQL, not Python. 3. Tests with freezegun (already a project dependency) covering tie-breaking and missing timestamps.
Author
Collaborator

Design note (corrects the findings comment)

The findings proposed ordering by COALESCE(updated, created) — but the schema check shows articles have no updated_at column (only aggregates and feeds do). The recency fields on articles are published_at (nullable) and created_at (fetch time, NOT NULL).

Design: get_articles_in_aggregate joins to articles and orders by COALESCE(published_at, created_at) DESC, created_at DESC — matching the house precedent in the other article-list queries (published_at DESC NULLS LAST, created_at DESC). Articles without a publish date sort by fetch time; ties break on fetch time. This also fixes the featured-image choice on the reader index, which takes the first article's image — it will now feature the newest article's image.

## Design note (corrects the findings comment) The findings proposed ordering by `COALESCE(updated, created)` — but the schema check shows **articles have no `updated_at` column** (only `aggregates` and `feeds` do). The recency fields on `articles` are `published_at` (nullable) and `created_at` (fetch time, NOT NULL). Design: `get_articles_in_aggregate` joins to `articles` and orders by `COALESCE(published_at, created_at) DESC, created_at DESC` — matching the house precedent in the other article-list queries (`published_at DESC NULLS LAST, created_at DESC`). Articles without a publish date sort by fetch time; ties break on fetch time. This also fixes the featured-image choice on the reader index, which takes the first article's image — it will now feature the newest article's image.
Author
Collaborator

Resolved by PR (merged): get_articles_in_aggregate now orders by COALESCE(published_at, created_at) DESC, created_at DESC, article_id DESC — newest first, with deterministic tie-breaking.

Resolved by PR (merged): `get_articles_in_aggregate` now orders by `COALESCE(published_at, created_at) DESC, created_at DESC, article_id DESC` — newest first, with deterministic tie-breaking.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
marvin8/yunjin#19
No description provided.