[PR #2402] [MERGED] Clean up NPC avatar files on re-upload and chat delete #5584

Closed
opened 2026-10-22 04:17:35 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2402
Author: @Romuromylus
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/npc-avatar-cleanup


📝 Commits (1)

  • 1bbdbc9 Clean up NPC avatar files on re-upload and chat delete

📊 Changes

2 files changed (+72 additions, -0 deletions)

View changed files

📝 src-tauri/src/commands/storage/avatars.rs (+68 -0)
📝 src-tauri/src/commands/storage/chats.rs (+4 -0)

📄 Description

Linked issue

Closes #2329

Why this change

  • NPC avatar files (avatars/npc/{chatId}-{name}-{millis}.{ext}) leaked two ways: every regen wrote a fresh timestamped file without removing the prior one, and chat deletion never swept them. NPC avatars live inline in chat metadata (gameNpcs / presentCharacters), not as tracked records, so no managed-file cleanup hook ever fired. Pure disk accumulation (low severity, no correctness impact).

What changed

  • src-tauri/src/commands/storage/avatars.rs: update_npc_avatar now removes older files for the same chat+name that the regen superseded, keeping only the just-written file (mirrors update_character_avatar_inner's prior-file cleanup). Matching uses safe_filename("{chat_id}-{name}") + - delimiter so "Rin" can't match "Rina", and excludes the kept filename by exact name.
  • src-tauri/src/commands/storage/chats.rs: delete_chat_with_messages best-effort scans avatars/npc/ by deleted {chat_id}- prefix (chat ids are UUIDs), mirroring delete_gallery_for_chats.
  • Both paths are best-effort: a missing directory or per-file removal error is logged and ignored, never propagated, so disk hygiene can't abort the main operation.

Refactor impact

Primary owner: Rust storage

Impact areas reviewed:

  • src-tauri/src/commands/storage/avatars.rs (update_npc_avatar + new prefix-scan helpers)
  • src-tauri/src/commands/storage/chats.rs (delete_chat_with_messages)

Boundary notes:

  • None. Additive helpers; neither function's JSON return contract changes. No retroactive sweep of pre-existing orphans (out of scope).

Pressure points touched:

  • None.

Validation

  • Matching validation command passes locally
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine (npc_avatar / delete_chat filters) — pass; existing avatar/gallery/delete tests stay green. Local-only tests confirmed re-upload removes the prior file, preserves a different name, and chat delete removes the chat's NPC avatars.
  • cargo clippy --manifest-path src-tauri/Cargo.toml --workspace --all-targets -- -D warnings — clean.

Feature Discoverability

  • Updated src/features/shell/discovery/
  • N/A because this PR is a disk-hygiene bugfix.

Reason:

  • No user-facing surface change.

Docs and release impact

  • No docs changes needed

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/2402 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/npc-avatar-cleanup` --- ### 📝 Commits (1) - [`1bbdbc9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1bbdbc9a9ee3789a1e2b754429f4ac16ca8803d6) Clean up NPC avatar files on re-upload and chat delete ### 📊 Changes **2 files changed** (+72 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/avatars.rs` (+68 -0) 📝 `src-tauri/src/commands/storage/chats.rs` (+4 -0) </details> ### 📄 Description ## Linked issue Closes #2329 ## Why this change - NPC avatar files (`avatars/npc/{chatId}-{name}-{millis}.{ext}`) leaked two ways: every regen wrote a fresh timestamped file without removing the prior one, and chat deletion never swept them. NPC avatars live inline in chat metadata (`gameNpcs` / `presentCharacters`), not as tracked records, so no managed-file cleanup hook ever fired. Pure disk accumulation (low severity, no correctness impact). ## What changed - `src-tauri/src/commands/storage/avatars.rs`: `update_npc_avatar` now removes older files for the same chat+name that the regen superseded, keeping only the just-written file (mirrors `update_character_avatar_inner`'s prior-file cleanup). Matching uses `safe_filename("{chat_id}-{name}")` + `-` delimiter so "Rin" can't match "Rina", and excludes the kept filename by exact name. - `src-tauri/src/commands/storage/chats.rs`: `delete_chat_with_messages` best-effort scans `avatars/npc/` by deleted `{chat_id}-` prefix (chat ids are UUIDs), mirroring `delete_gallery_for_chats`. - Both paths are best-effort: a missing directory or per-file removal error is logged and ignored, never propagated, so disk hygiene can't abort the main operation. ## Refactor impact Primary owner: Rust storage Impact areas reviewed: - `src-tauri/src/commands/storage/avatars.rs` (`update_npc_avatar` + new prefix-scan helpers) - `src-tauri/src/commands/storage/chats.rs` (`delete_chat_with_messages`) Boundary notes: - None. Additive helpers; neither function's JSON return contract changes. No retroactive sweep of pre-existing orphans (out of scope). Pressure points touched: - None. ## Validation - [x] Matching validation command passes locally - [ ] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine` (npc_avatar / delete_chat filters) — pass; existing avatar/gallery/delete tests stay green. Local-only tests confirmed re-upload removes the prior file, preserves a different name, and chat delete removes the chat's NPC avatars. - `cargo clippy --manifest-path src-tauri/Cargo.toml --workspace --all-targets -- -D warnings` — clean. ## Feature Discoverability - [ ] Updated `src/features/shell/discovery/` - [x] N/A because this PR is a disk-hygiene bugfix. Reason: - No user-facing surface change. ## Docs and release impact - [x] No docs changes needed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:35 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5584
No description provided.