Skip to content

Bug/Feature: Actor "Ghost/Resurrection" bug caused by FirstOrCreate in ReapplyEdits() & Feature Request for JAV Kanji names #2212

Description

@usaretama77

Description of the Bug: The "Ghost/Resurrection" Actor Bug

For a long time,
Asian users (or anyone who prefers organizing Japanese performers by their native Kanji names) have suffered from a persistent bug where previously deleted English/Romaji actor tags randomly "reincarnate" or "resurrect" into scene casts.

Even if we manually clean up the Cast field in a scene, change the actor's name to Japanese Kanji (e.g., 初美沙希),
and completely Delete the old Romaji actor profile (e.g., Hatsumi Saki) from the global Actors list,
the deleted Romaji tag will completely reappear out of nowhere after running a new Scrape task (even when scraping unrelated Western scenes) or during global synchronization.


Deep Dive: The Root Cause in Code

Thanks to deep investigation into the codebase,
we have successfully pinpointed the exact code-level trigger chain responsible for this bug:

Trigger Chain: tasks.Scrape*content.go:367 ReapplyEdits()actions table replay ➔ FirstOrCreate resurrects deleted Romaji actor.

📊 Code Execution Flow & Bug Trigger Chain:

[Task Triggered]
   │
   ▼
tasks.Scrape* (Manual single scene scrape or global background sync)
   │
   ▼
content.go:367 -> ReapplyEdits() 
   │
   ▼
[Replay History] 
Reads 'actions' table -> Fetches original metadata (e.g., "Hatsumi Saki")
   │
   ▼
[Database Query via GORM]
db.Where("name = ?", actorName).FirstOrCreate(&actor)
   │
   ├───► 1. .First()  -> Query global database for "Hatsumi Saki"
   │                     (Result: NOT FOUND, because user deleted it)
   │
   └───► 2. .OrCreate() -> Failsafe triggers! Automatically creates a 
                          BRAND NEW, blank "Hatsumi Saki" actor record.
   │
   ▼
[The Resurrection]
Ghost actor tag is successfully re-attached to the scene's Cast field.

Code Investigation Reference:

**

<img width="798" height="490" alt="Image" src="https://github.com/user-attachments/assets/d15d5b6b-91b9-47cb-9b84-fe26641e8c0e" />
<img width="802" height="906" alt="Image" src="https://github.com/user-attachments/assets/f68f721b-fc91-4a10-bdc1-8eef654bf056" />

**

```markdown
### The Code Breakdown:
In `pkg/content/content.go` (around lines 366-368), inside the `ReapplyEdits()` function:

```go
// From the codebase investigation:
for _, actorName := range scene.ActorNames {
    var actor models.Actor
    db.Where("name = ?", actorName).FirstOrCreate(&actor) // 💥 CRITICAL BUG HERE
    // ... logic to link actor to scene
}

ReapplyEdits() Mechanism: When a scrape task runs, 
XBVR attempts to reapply historical scene modifications by replaying entries stored in the actions table (or original scraper JSON caches) to ensure user edits aren't overwritten.

The actions Table Legacy: The original scrape payload forever contains the Romaji name (e.g., Hatsumi Saki) assigned by the scraper at that time.

The FirstOrCreate Blind Spot:
When ReapplyEdits() replays the action, it asks GORM's FirstOrCreate to look for an actor named Hatsumi Saki.
Since the user already went to the Actors UI and Deleted the Hatsumi Saki global record, GORM's .First() query returns empty.
Consequently, .OrCreate() automatically kicks in and creates a brand new, empty, detached duplicate Actor entity in the database and re-attaches it to the scene's cast.
This creates an endless loop of ghost tags that users can never truly eliminate through the UI.
Proposed Fix for the Bug

Instead of unconditionally calling FirstOrCreate using historical scraper metadata, the ReapplyEdits() logic should:
Check if the actor name matches an existing Alias of an existing actor (e.g., if Hatsumi Saki is an alias under 初美沙希, map it to 初美沙希).
If the actor record was explicitly deleted by the user and no alias exists, 
it should respect the user's deletion instead of forcefully creating a new ghost record via FirstOrCreate.

Feature Request: Default Kanji Names for JAV Scrapers
To radically prevent this name mismatch and reduce the nightmare of manual cleanup for non-English speakers, 
we would love to request a new feature:

Request: Please add a configuration setting/toggle for JAV scrapers (such as javdatabase, etc.) allowing users to select their preferred Cast Name Format.
Options:
Romaji (Default) (e.g., Hatsumi Saki)
Native Japanese Kanji (e.g., 初美沙希)
If the scraper can fetch and apply the Kanji names natively right from the beginning, 
it will drastically improve the experience for Asian communities and prevent the massive tag pollution altogether.
Thank you for your amazing work on XBVR, and we hope this detailed code-level breakdown helps resolve this long-standing issue in the upcoming releases!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions