ankitects / ankitects/anki

Schema-11 downgrade leaves SQLite freelist waste in .apkg exports

オープン
#5,490 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
30.5k
フォーク
3.2k
平均マージ
2日 8時間
マージ済み PR(30日)
60

説明

The schema-11 downgrade (`schema11_downgrade.sql`) drops tables and indexes, which leaves pages on the SQLite freelist without shrinking the file.

This affects `.apkg` exports in two places:
- **Legacy exports:** the main `collection.anki21` is downgraded to V11 before being copied, so it carries freelist pages.
- **Both legacy and non-legacy exports:** every package includes a dummy `collection.anki2` that is built at V18, vacuumed, then downgraded to V11 — the downgrade re-creates freelist pages after the vacuum.

Non-legacy main DBs (`collection.anki21b`) are unaffected because closing at V18 is a no-op.

**Real-world example:** the [UK Geography | Regions, Counties, and Cities](https://ankiweb.net/shared/info/80961363) shared deck (~200 notes), exported from the same build with and without a workaround:

| Export | Before | After manual VACUUM | Saving |
|---|---|---|---|
| Legacy (compatibility) | 751 KB | 706 KB | ~46 KB (~6%) |
| Non-legacy (zstd) | 269 KB | 240 KB | ~29 KB (~11%) |

Freelist pages observed in the exported packages:
- Legacy: `collection.anki21` had 37 free pages; dummy `collection.anki2` had 56.
- Non-legacy: `collection.anki21b` had 0 free pages; dummy `collection.anki2` had 56.

Proposed fix: run `VACUUM` after the downgrade transaction commits in `downgrade_to_schema_11`, so both the exported legacy DB and the dummy collection are compact.

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

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

調査の方向性

Start with schema11_downgrade.sql and the downgrade_to_schema_11 entry point, then trace the export paths for collection.anki21 and the dummy collection.anki2. Verify the transaction boundary and run an export using the affected paths. Done means the downgraded databases are compact and no longer contain the reported freelist pages.

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

評価

技術スタック
rust, sqlite
領域
database
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
76/100

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

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