Skip to content

Commit 479241a

Browse files
leftzzzzhuang letian
authored andcommitted
modify: fix delete fragment unexpectedly
1 parent 049f75e commit 479241a

23 files changed

+90
-26
lines changed

backend/magic-service/app/Application/KnowledgeBase/Event/Subscribe/KnowledgeBaseFragmentDestroySubscriber.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ public function process(object $event): void
4646
$dataIsolation = KnowledgeBaseDataIsolation::create()->disabled();
4747

4848
try {
49-
// 删除相同内容的点
50-
$knowledge->getVectorDBDriver()->removePoints($knowledge->getCollectionName(), [$fragment->getPointId()]);
51-
$knowledgeBaseFragmentDomainService->batchDestroyByPointIds($dataIsolation, $knowledge, [$fragment->getPointId()]);
49+
$existFragments = $knowledgeBaseFragmentDomainService->getFragmentsByPointId($dataIsolation, $fragment->getKnowledgeCode(), $fragment->getPointId(), true);
50+
if (! empty($existFragments) && $existFragments[0]->getVersion() <= $fragment->getVersion()) {
51+
// 删除相同内容的点
52+
$knowledge->getVectorDBDriver()->removePoints($knowledge->getCollectionName(), [$fragment->getPointId()]);
53+
$knowledgeBaseFragmentDomainService->batchDestroyByPointIds($dataIsolation, $knowledge, [$fragment->getPointId()]);
54+
}
5255

5356
$fragment->setSyncStatus(KnowledgeSyncStatus::Deleted);
5457
} catch (Throwable $throwable) {

backend/magic-service/app/Application/KnowledgeBase/Service/AbstractKnowledgeAppService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use App\Application\Permission\Service\OperationPermissionAppService;
1515
use App\Domain\Contact\Service\MagicUserDomainService;
1616
use App\Domain\File\Service\FileDomainService;
17-
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\DocumentFileInterface;
17+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\DocumentFileInterface;
1818
use App\Domain\KnowledgeBase\Entity\ValueObject\KnowledgeBaseDataIsolation;
1919
use App\Domain\KnowledgeBase\Service\KnowledgeBaseDocumentDomainService;
2020
use App\Domain\KnowledgeBase\Service\KnowledgeBaseDomainService;

backend/magic-service/app/Application/KnowledgeBase/Service/KnowledgeBaseAppService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use App\Application\ModelGateway\Mapper\ModelGatewayMapper;
1111
use App\Domain\Contact\Entity\MagicUserEntity;
1212
use App\Domain\KnowledgeBase\Entity\KnowledgeBaseEntity;
13-
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\DocumentFileInterface;
13+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\DocumentFileInterface;
1414
use App\Domain\KnowledgeBase\Entity\ValueObject\Query\KnowledgeBaseQuery;
1515
use App\Domain\Permission\Entity\ValueObject\OperationPermission\Operation;
1616
use App\Domain\Permission\Entity\ValueObject\OperationPermission\ResourceType;

backend/magic-service/app/Application/KnowledgeBase/Service/KnowledgeBaseFragmentAppService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use App\Application\KnowledgeBase\VectorDatabase\Similarity\KnowledgeSimilarityFilter;
1111
use App\Application\KnowledgeBase\VectorDatabase\Similarity\KnowledgeSimilarityManager;
1212
use App\Domain\KnowledgeBase\Entity\KnowledgeBaseFragmentEntity;
13-
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\DocumentFileInterface;
13+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\DocumentFileInterface;
1414
use App\Domain\KnowledgeBase\Entity\ValueObject\FragmentConfig;
1515
use App\Domain\KnowledgeBase\Entity\ValueObject\KnowledgeRetrievalResult;
1616
use App\Domain\KnowledgeBase\Entity\ValueObject\Query\KnowledgeBaseFragmentQuery;

backend/magic-service/app/Application/KnowledgeBase/Service/Strategy/DocumentFile/DocumentFileStrategy.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use App\Application\KnowledgeBase\Service\Strategy\DocumentFile\Driver\Interfaces\ExternalFileDocumentFileStrategyInterface;
1212
use App\Application\KnowledgeBase\Service\Strategy\DocumentFile\Driver\Interfaces\ThirdPlatformDocumentFileStrategyInterface;
1313
use App\Domain\File\Service\FileDomainService;
14-
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\DocumentFileInterface;
15-
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\ExternalDocumentFile;
16-
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\ThirdPlatformDocumentFile;
14+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\DocumentFileInterface;
15+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\ExternalDocumentFileInterface;
16+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\ThirdPlatformDocumentFileInterface;
1717
use App\Domain\KnowledgeBase\Entity\ValueObject\KnowledgeBaseDataIsolation;
1818
use Dtyq\CloudFile\Kernel\Struct\UploadFile;
1919
use Hyperf\Logger\LoggerFactory;
@@ -192,9 +192,9 @@ private function getExtensionFromMimeType(string $mimeType): string
192192

193193
private function getImplement(?DocumentFileInterface $documentFile): ?BaseDocumentFileStrategyInterface
194194
{
195-
$interface = match (get_class($documentFile)) {
196-
ExternalDocumentFile::class => ExternalFileDocumentFileStrategyInterface::class,
197-
ThirdPlatformDocumentFile::class => ThirdPlatformDocumentFileStrategyInterface::class,
195+
$interface = match (true) {
196+
$documentFile instanceof ExternalDocumentFileInterface => ExternalFileDocumentFileStrategyInterface::class,
197+
$documentFile instanceof ThirdPlatformDocumentFileInterface => ThirdPlatformDocumentFileStrategyInterface::class,
198198
default => null,
199199
};
200200

backend/magic-service/app/Application/KnowledgeBase/Service/Strategy/DocumentFile/Driver/ExternalFileDocumentFileStrategyDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use App\Application\KnowledgeBase\Service\Strategy\DocumentFile\Driver\Interfaces\ExternalFileDocumentFileStrategyInterface;
1111
use App\Domain\File\Service\FileDomainService;
1212
use App\Domain\KnowledgeBase\Entity\ValueObject\DocType;
13-
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\DocumentFileInterface;
1413
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\ExternalDocumentFile;
14+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\DocumentFileInterface;
1515
use App\Domain\KnowledgeBase\Entity\ValueObject\KnowledgeBaseDataIsolation;
1616
use App\Infrastructure\Core\File\Parser\FileParser;
1717
use App\Infrastructure\Util\FileType;

backend/magic-service/app/Application/KnowledgeBase/Service/Strategy/DocumentFile/Driver/Interfaces/BaseDocumentFileStrategyInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace App\Application\KnowledgeBase\Service\Strategy\DocumentFile\Driver\Interfaces;
99

10-
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\DocumentFileInterface;
10+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\DocumentFileInterface;
1111
use App\Domain\KnowledgeBase\Entity\ValueObject\KnowledgeBaseDataIsolation;
1212

1313
interface BaseDocumentFileStrategyInterface

backend/magic-service/app/Application/KnowledgeBase/Service/Strategy/DocumentFile/Driver/ThirdPlatformDocumentFileStrategyDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use App\Application\KnowledgeBase\Service\Strategy\DocumentFile\Driver\Interfaces\ThirdPlatformDocumentFileStrategyInterface;
1111
use App\Domain\KnowledgeBase\Entity\ValueObject\DocType;
12-
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\DocumentFileInterface;
12+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\DocumentFileInterface;
1313
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\ThirdPlatformDocumentFile;
1414
use App\Domain\KnowledgeBase\Entity\ValueObject\KnowledgeBaseDataIsolation;
1515

backend/magic-service/app/Domain/KnowledgeBase/Entity/KnowledgeBaseDocumentEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace App\Domain\KnowledgeBase\Entity;
99

1010
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\AbstractDocumentFile;
11-
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\DocumentFileInterface;
11+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\DocumentFileInterface;
1212
use App\Domain\KnowledgeBase\Entity\ValueObject\FragmentConfig;
1313
use App\Domain\KnowledgeBase\Entity\ValueObject\RetrieveConfig;
1414
use App\ErrorCode\FlowErrorCode;

backend/magic-service/app/Domain/KnowledgeBase/Entity/ValueObject/DocumentFile/AbstractDocumentFile.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile;
99

10+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\DocumentFileInterface;
11+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\ExternalDocumentFileInterface;
12+
use App\Domain\KnowledgeBase\Entity\ValueObject\DocumentFile\Interfaces\ThirdPlatformDocumentFileInterface;
1013
use App\Infrastructure\Core\AbstractValueObject;
1114

1215
abstract class AbstractDocumentFile extends AbstractValueObject implements DocumentFileInterface
@@ -70,8 +73,8 @@ public static function fromArray(array $data): ?DocumentFileInterface
7073
$documentFileType = isset($data['type']) ? DocumentFileType::tryFrom($data['type']) : DocumentFileType::EXTERNAL;
7174
$data['type'] = $documentFileType;
7275
return match ($documentFileType) {
73-
DocumentFileType::EXTERNAL => new ExternalDocumentFile($data),
74-
DocumentFileType::THIRD_PLATFORM => new ThirdPlatformDocumentFile($data),
76+
DocumentFileType::EXTERNAL => make(ExternalDocumentFileInterface::class, [$data]),
77+
DocumentFileType::THIRD_PLATFORM => make(ThirdPlatformDocumentFileInterface::class, [$data]),
7578
default => null,
7679
};
7780
}

0 commit comments

Comments
 (0)