Repository navigation
Save images in parallel - #6
Conversation
The database writer used to save every image to disk one at a time, so the concurrency limit only applied to downloads. On a network share, that held the crawl to about 7 images a second. Each download task now saves its own image and sends only the results to the writer. Each save also gets its own temporary name, so two rows that share an image can't overwrite each other's partial file. In a trial against the same share at --concurrency=32, the rate reached about 25 images a second while the running crawl kept its 7. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 078a5d27b1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let id = NEXT_TEMP_ID.fetch_add(1, Ordering::Relaxed); | ||
| let temp_path = file_path.with_extension(format!("{id}.part")); | ||
| std::fs::write(&temp_path, bytes)?; |
There was a problem hiding this comment.
Remove the temporary file when writing fails
If a write fails after creating a partial file—for example, when the network share disconnects mid-write—the ? returns without removing it. Because each attempt now uses a new ID, subsequent crawl cycles leave that partial file behind even when the image eventually saves successfully; previously, the retry reused and replaced the same .part file. Repeated write failures can therefore accumulate orphaned image data and consume the share's free space. Clean up the temporary file on write errors as well as rename errors.
Useful? React with 👍 / 👎.
Each save has its own temporary name, so a partial file from a failed write would otherwise stay on the share. Also adds zsh to the Vale vocabulary, which the CI's Vale version doesn't know. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* Document where to save the TMDB API key The docs told readers to export a key but never said which TMDB value to use or how to keep it out of shell history. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Match TMDBHelper schema version 50 and fix the crawl's data bugs The add-on ignored everything warmup-rs wrote: `baseitem.language` held each title's original language, while the add-on's query needs its own language setting. Collections used the wrong ID, and rows in `ratings` stopped the add-on fetching ratings. - Port the add-on's `mappings.py` to one writer, including seasons, episodes, episode groups, and schema version 50. - Download every image at `original` and delete older `w1280` files. - Keep in-flight items in the queue, so a stop loses nothing. - Drop 404s and items that keep failing instead of retrying forever. - Exit on a rejected API key, and keep the key out of error logs. - Add `--all-ids`, `--language`, and `--min-free-gb`. - Lower the default concurrency to 20, which avoids TMDB's rate limit. - Make the TMDB tests explicit with `just test-live`, since they passed without checking anything when no key was set. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Speed up the database writer and the image purge The writers cycle through more prepared statements than rusqlite's default cache of 16 holds, so most writes recompiled their SQL. A larger cache takes a write from 128 ms to about 8 ms per item. The purge scanned the whole texture table for each file it removed, so it now deletes by row ID. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Document how to split disk space between the two crawls Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Add a fanart.tv crawl and match Kodi's texture rows With its fanart.tv lookup on, TMDBHelper ignores a movie or show until `baseitem.fanart_tv` is set. On Kodi 21.3 with those settings, flagged rows served from the cache in 0.3 s, and unflagged rows were fetched again. `--mode=fanart` fetches the art and sets the flag, and images mode now caches fanart.tv URLs too. New texture rows leave `lasthashcheck` empty, which is what Kodi stores for web images. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Accept fanart in the Vale vocabulary Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Document keeping images on a network share Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Read free space with 64-bit block counts on macOS macOS keeps `statvfs` block counts in 32 bits, and an SMB share reports 1 KB blocks, so a share with 5 TB free read as about 1 TB and images mode paused. Also fix a stray code fence in the quick start. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Save images in parallel (#6) * Save images in parallel The database writer used to save every image to disk one at a time, so the concurrency limit only applied to downloads. On a network share, that held the crawl to about 7 images a second. Each download task now saves its own image and sends only the results to the writer. Each save also gets its own temporary name, so two rows that share an image can't overwrite each other's partial file. In a trial against the same share at --concurrency=32, the rate reached about 25 images a second while the running crawl kept its 7. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Remove the temporary image file when a save fails Each save has its own temporary name, so a partial file from a failed write would otherwise stay on the share. Also adds zsh to the Vale vocabulary, which the CI's Vale version doesn't know. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Fix five crawl bugs from review - A real external ID now replaces the "None" that a null one left, so a later refresh can add a missing IMDb or TVDB ID. - Watch providers are written in the add-on's order (flatrate, free, ads, rent, buy), so a subscription isn't stored as buy-only. - TMDB server errors that outlast the retries count as an outage, and the item goes back in the queue instead of toward failed. - The free-space check uses the current folder when a database path has no folder, instead of skipping the check. - addon-schema.py keeps the quoted language and country seed rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gW5bMySbSKFF1ZGDNn * Keep the databases intact through a crash or forced restart All three databases ran WAL with synchronous=OFF, and a forced restart of the Mac during the full crawl left ItemDetails.db and state.db malformed. They now use synchronous=NORMAL, which can lose the last few transactions in a crash but not corrupt the file, plus fullfsync and checkpoint_fullfsync, because a plain fsync on macOS leaves data in the drive's cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gW5bMySbSKFF1ZGDNn * Requeue items when their cache expires, not only after 30 days Ongoing shows, seasons, and episodes expire after 7 days, but the crawler only requeued items 30 days after their visit. When the seeder runs, it now also reads the expired rows from ItemDetails.db and puts those items back in the queue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gZSSKSAXLazAYpSG4A * Keep blank-role credits unique and expand items at their shallowest depth - A person's filmography wrote a new cast or crew row on every refresh when the role or department was blank, because NULL never matches the unique key. It now checks for the credit first. - An item found closer to a seed while it was being fetched kept its deeper depth, so its children could be dropped. The writer now reads the item's current queue depth before it expands it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gZSSKSAXLazAYpSG4A * Seed popular titles before the exports, and find all legacy w1280 files - With --all-ids, the full exports filled the queue before the popular seeds were fetched, so the crawl no longer started with them. The popular seeds are now queued at depth 0 before the exports. - The purge only recognized files downloaded at w1280 when that URL was registered, which older builds didn't do for posters, profiles, and logos. It now builds the w1280 URL from any registered size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gZSSKSAXLazAYpSG4A --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Requested by xbmc4lyfe
Summary
The image crawl downloaded in parallel but saved every file through one writer, so a network share limited it to about 7 images a second however high
--concurrencywent. Each download task now saves its own image while it holds its slot, and the writer only handles the database batches.--concurrencynow limits downloads and saves together.This targets
claude/addon-v50-full-cache, because the running crawl uses that branch's code.Testing
--concurrency=32for about 6.5 minutes after startup, with the live crawl and the NAS's other load still running: 9,511 images saved, about 25 a second, reaching about 31 a second late in the run, and no write errors. The live crawl stayed at about 7 a second, so the share handled about 32 a second in total.just lint,cargo test, andjust vale-lintpass.Not tested: a full crawl cycle to completion.
🤖 Generated with Claude Code