Files
FredApps 9818c45071 cli: use tokio file I/O and sleep inside async functions (Sonar S7493/S7488) (#365)
## Summary

Replaces blocking calls inside `async fn`s in the production CLI tools
with their tokio equivalents. This resolves 16 SonarCloud findings:
**rust:S7493** (blocking file operation in async code) and
**rust:S7488** (`std::thread::sleep` in async code).

| Tool | File | Rule | Change |

|---------------------|-------------------------------------------------------------------------|-------|--------|
| `support-tool` | `kinovi_web/subcommands/audit_credits.rs`,
`audit_orders.rs`, `audit_payments.rs` | S7493 × 9 | `std::fs::metadata`
/ `OpenOptions::open` / `writeln!` → `tokio::fs` + `AsyncWriteExt` |
| `elasticsearch-cli` | `plans/create_all_tts_documents.rs`,
`media_files/create_dimensional_media_file_documents.rs`,
`model_weights/create_all_model_weight_documents.rs` | S7493 × 3 |
`std::fs::read_to_string` → `tokio::fs::read_to_string(..).await` |
| `db-cleanup` | `delete_all_anonymous_user_images.rs`,
`migrate_media_files_enum_values/query_pair.rs` | S7488 × 2 |
`thread::sleep` → `tokio::time::sleep(..).await` |
| `migration-tool` | `tts_models_to_weights/migrate.rs`,
`voice_conversion_to_weights/migrate.rs` | S7488 × 2 | `thread::sleep` →
`tokio::time::sleep(..).await` |

In the three `support-tool` audit commands, the CSV is still opened in
append mode, the header is still written only when the file is new or
empty, and the file is still flushed after every page. The row helpers
(`write_*_row`) stay synchronous and now write into a per-page
`Vec<u8>`. That buffer is appended to the file with one
`write_all(..).await` before the per-page flush, so rows reach disk at
the same points as before.

Sleep durations are unchanged. The `tokio` features each crate now needs
(`fs`, `io-util`, `time`) are declared in its `Cargo.toml`. `Cargo.lock`
does not change.

## Not included (overlap with open PRs)

- `db-cleanup/.../delete_user_files.rs:71` (S7488): #324 edits the lines
around this `thread::sleep`.
- `support-tool/.../kinovi_web/subcommands/generate_video.rs:349`
(S7493): #308 rewrites this media-cache write.

#253 also touches `delete_all_anonymous_user_images.rs`, but only the
query filter near the top of the loop (lines 17–57). The sleep at line
65 is outside its hunks.

## Testing

Run locally on Linux x86_64 with stable Rust and `SQLX_OFFLINE=true`:

- `cargo check -p support-tool -p elasticsearch-cli -p db-cleanup -p
migration-tool` passes.
- `cargo test` on the same four crates passes (13 unit tests).
- `cargo clippy` on the same crates, run with `-A
clippy::deprecated_semver` for a pre-existing error in `enums`, reports
nothing on the changed lines.

No new tests are added. The changed functions talk to MySQL,
Elasticsearch or the Kinovi web API, and have no offline harness. The
switch to non-blocking calls does not change observable behaviour, so
there is no test that fails before the change and passes after it.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Refactor**
* Database cleanup and migration tasks now wait asynchronously between
attempts, helping keep command execution responsive.
* Search-index setup and support-tool audit exports now use asynchronous
file operations.
* Audit reports continue to append to existing files, add headers when
needed, and include the same qualifying records; output is written in
batches.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-10 18:28:26 +01:00
..