Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

CleanOrphanUploadFiles may skip records when using offset pagination

オープン
#1,631 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go
領域
backend, databases

調査の方向性

Start at the CleanOrphanUploadFiles entry point and trace its batch query and interaction with DeleteAndMoveFileRecord. Verify the cleanup continues scanning all records eligible at the start of the run, including the 1001-record reproduction case, without leaving an eligible record Available.

索引モデルが issue の本文から書いたものです。

説明

bug

Describe the bug

CleanOrphanUploadFiles may skip some available file records during a cleanup run because it uses offset-based pagination while modifying the same result set being paginated.

The cleanup job queries file records with status = Available in batches of 1000. While processing a batch, orphan files are cleaned by DeleteAndMoveFileRecord, which changes their status from Available to Deleted.

Because those records no longer match the status = Available condition, the result set becomes smaller. However, the next iteration increments the page number and continues using an offset calculated from the new result set.

For example, if there are 1001 eligible orphan records:

  • Page 1 queries the first 1000 records with OFFSET 0.
  • Those 1000 records are changed from Available to Deleted.
  • Only 1 Available record remains.
  • Page 2 queries with OFFSET 1000.
  • The remaining record is skipped, so the query returns no records and the cleanup loop exits.

As a result, not all eligible orphan file records are guaranteed to be checked in a single cleanup run. The skipped records remain Available and may only be processed by a later cleanup run.

To Reproduce

Steps to reproduce the behavior:

  1. Create 1001 file records with:

    • status = Available
    • CreatedAt older than 2 days
    • no revision or other object referencing the uploaded file
    • corresponding uploaded files present on disk
  2. Run CleanOrphanUploadFiles.

  3. Query the remaining file records with status = Available.

  4. Observe that at least one eligible orphan record remains unprocessed.

The issue comes from combining offset pagination with updates to the filtered result set:

First query:
OFFSET 0 LIMIT 1000
→ 1000 records are processed
→ their status changes from Available to Deleted

Remaining Available records:
1

Second query:
OFFSET 1000 LIMIT 1000
→ returns no records
→ cleanup exits

Expected behavior

CleanOrphanUploadFiles should scan all file records that are eligible for the current cleanup run, even when previously scanned records are changed from Available to Deleted.

No eligible record should be skipped because earlier records were removed from the Available result set during the same cleanup execution.

Screenshots

Not applicable.

Platform

  • Device: N/A
  • OS: Not OS-specific
  • Browser and version: N/A
  • Version: current main (3b9f1370612e690a0b7f230f05e688930db4c6d3)
  • Deployment method: Source
主要言語
Go
スター
15.7k
フォーク
1.4k
平均マージ
1日 20時間
マージ済み PR(30日)
6

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/answer のほかの issue

apache/answer の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。