harden document delete and rebuild faiss index
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@@ -31,10 +30,18 @@ class Document
|
||||
#[ORM\Column]
|
||||
private \DateTimeImmutable $createdAt;
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'document', targetEntity: DocumentVersion::class, cascade: ['persist'], orphanRemoval: true)]
|
||||
// 🔥 REMOVE ergänzt
|
||||
#[ORM\OneToMany(
|
||||
mappedBy: 'document',
|
||||
targetEntity: DocumentVersion::class,
|
||||
cascade: ['persist', 'remove'],
|
||||
orphanRemoval: true
|
||||
)]
|
||||
private Collection $versions;
|
||||
|
||||
// 🔥 onDelete ergänzt
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
|
||||
private ?DocumentVersion $currentVersion = null;
|
||||
|
||||
public function __construct()
|
||||
@@ -65,7 +72,6 @@ class Document
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->status;
|
||||
@@ -94,8 +100,10 @@ class Document
|
||||
|
||||
public function addVersion(DocumentVersion $version): void
|
||||
{
|
||||
$this->versions->add($version);
|
||||
$version->setDocument($this);
|
||||
if (!$this->versions->contains($version)) {
|
||||
$this->versions->add($version);
|
||||
$version->setDocument($this);
|
||||
}
|
||||
}
|
||||
|
||||
public function setCurrentVersion(?DocumentVersion $version): void
|
||||
|
||||
@@ -97,27 +97,8 @@ class DocumentService
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* HARD DELETE
|
||||
*
|
||||
* Entfernt das Dokument vollständig aus der Datenbank.
|
||||
* Chunks und Vector-Index werden NICHT hier behandelt,
|
||||
* sondern im Ingest-Job (TYPE_DOCUMENT_DELETE).
|
||||
*/
|
||||
public function delete(Document $document): void
|
||||
{
|
||||
// 1. FK-Zyklus auflösen
|
||||
$document->setCurrentVersion(null);
|
||||
$this->em->flush(); // <-- WICHTIG: zuerst FK nullen!
|
||||
|
||||
// 2. Versionen entfernen (falls kein cascade remove existiert)
|
||||
foreach ($document->getVersions() as $version) {
|
||||
$this->em->remove($version);
|
||||
}
|
||||
|
||||
$this->em->flush(); // <-- Versionen löschen
|
||||
|
||||
// 3. Dokument löschen
|
||||
$this->em->remove($document);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user