Skip to content

fix: created_at ordering for file listings#3437

Merged
HFO4 merged 1 commit into
cloudreve:masterfrom
yindaheng98:master
May 9, 2026
Merged

fix: created_at ordering for file listings#3437
HFO4 merged 1 commit into
cloudreve:masterfrom
yindaheng98:master

Conversation

@yindaheng98

Copy link
Copy Markdown
Contributor

Summary

This PR fixes file listing order when order_by=created_at is requested.

image

Previously, created_at was not mapped to the actual file order options, so both offset and cursor pagination could fall back to ID ordering instead of sorting by created_at. This change adds proper created_at sorting, fixes the cursor predicate for created_at, and includes created_at in the next-page token so pagination remains stable across pages.

Testing

  • Added regression tests for created_at sorting in offset pagination
  • Added regression tests for created_at cursor pagination
  • Verified API behavior with Docker-based read/write testing

Affected APIs

This change affects the file listing API:

  • GET /api/v4/file

The fix applies when using query parameters such as:

  • uri
  • page
  • page_size
  • order_by=created_at
  • order_direction=asc|desc
  • next_page_token

In particular, it fixes:

  • incorrect fallback to ID ordering when order_by=created_at is requested
  • unstable cursor pagination for created_at sorting across pages

@CLAassistant

CLAassistant commented Apr 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@YUDONGLING

Copy link
Copy Markdown
Member

create_at is the time when record is inserted into the database, and id is auto-incrementing, thus the two are equivalent.

Let's wait for further discussion to see if this is by design or a missing piece.

@yindaheng98

Copy link
Copy Markdown
Contributor Author

修复后
image

@yindaheng98

Copy link
Copy Markdown
Contributor Author

create_at is the time when record is inserted into the database, and id is auto-incrementing, thus the two are equivalent.

Let's wait for further discussion to see if this is by design or a missing piece.

Thanks for the clarification. I agree that for normally uploaded files, "created_at" and auto-incrementing "id" should usually be equivalent.

I noticed this while writing a tool to index external files without copying them. The tool writes records directly and syncs filesystem timestamps into the database, so "created_at" may differ from insertion order. In that case, falling back to "id" ordering gives unexpected results.

So this likely does not affect normal uploads, but matters for external indexing/import workflows.

@HFO4

HFO4 commented May 9, 2026

Copy link
Copy Markdown
Member

Good catch! I feeels we need to add a new index for (file_children, type, created_at), but let me address this in a seperate commit.

@HFO4 HFO4 added this to the v4.16.0 milestone May 9, 2026
@HFO4 HFO4 merged commit c33273b into cloudreve:master May 9, 2026
1 of 2 checks passed
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.

4 participants