mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 06:54:28 +00:00
Merge pull request #206 from shumaiOne/fix/latest-children-trashed-files
fix(asset): exclude soft-deleted children from latestChildren preview
This commit is contained in:
@@ -102,6 +102,7 @@ export class AssetService {
|
|||||||
metadataValues: true,
|
metadataValues: true,
|
||||||
storageKey: true,
|
storageKey: true,
|
||||||
children: {
|
children: {
|
||||||
|
where: { isDeleted: false },
|
||||||
include: { creator: true, metadataValues: true, storageKey: true },
|
include: { creator: true, metadataValues: true, storageKey: true },
|
||||||
take: 3,
|
take: 3,
|
||||||
orderBy: { sortIndex: 'asc' },
|
orderBy: { sortIndex: 'asc' },
|
||||||
@@ -109,6 +110,7 @@ export class AssetService {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
children: {
|
children: {
|
||||||
|
where: { isDeleted: false },
|
||||||
include: { creator: true, metadataValues: true, storageKey: true },
|
include: { creator: true, metadataValues: true, storageKey: true },
|
||||||
take: 3,
|
take: 3,
|
||||||
orderBy: { sortIndex: 'asc' },
|
orderBy: { sortIndex: 'asc' },
|
||||||
@@ -661,6 +663,7 @@ export class AssetService {
|
|||||||
metadataValues: true,
|
metadataValues: true,
|
||||||
storageKey: true,
|
storageKey: true,
|
||||||
children: {
|
children: {
|
||||||
|
where: { isDeleted: false },
|
||||||
include: { creator: true, metadataValues: true, storageKey: true },
|
include: { creator: true, metadataValues: true, storageKey: true },
|
||||||
take: 3,
|
take: 3,
|
||||||
orderBy: { sortIndex: 'asc' },
|
orderBy: { sortIndex: 'asc' },
|
||||||
@@ -668,6 +671,7 @@ export class AssetService {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
children: {
|
children: {
|
||||||
|
where: { isDeleted: false },
|
||||||
include: { creator: true, metadataValues: true, storageKey: true },
|
include: { creator: true, metadataValues: true, storageKey: true },
|
||||||
take: 3,
|
take: 3,
|
||||||
orderBy: { sortIndex: 'asc' },
|
orderBy: { sortIndex: 'asc' },
|
||||||
@@ -745,6 +749,7 @@ export class AssetService {
|
|||||||
metadataValues: true,
|
metadataValues: true,
|
||||||
storageKey: true,
|
storageKey: true,
|
||||||
children: {
|
children: {
|
||||||
|
where: { isDeleted: false },
|
||||||
include: { creator: true, metadataValues: true, storageKey: true },
|
include: { creator: true, metadataValues: true, storageKey: true },
|
||||||
take: 3,
|
take: 3,
|
||||||
orderBy: { sortIndex: 'asc' },
|
orderBy: { sortIndex: 'asc' },
|
||||||
@@ -752,6 +757,7 @@ export class AssetService {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
children: {
|
children: {
|
||||||
|
where: { isDeleted: false },
|
||||||
include: { creator: true, metadataValues: true, storageKey: true },
|
include: { creator: true, metadataValues: true, storageKey: true },
|
||||||
take: 3,
|
take: 3,
|
||||||
orderBy: { sortIndex: 'asc' },
|
orderBy: { sortIndex: 'asc' },
|
||||||
@@ -794,6 +800,7 @@ export class AssetService {
|
|||||||
metadataValues: true,
|
metadataValues: true,
|
||||||
storageKey: true,
|
storageKey: true,
|
||||||
children: {
|
children: {
|
||||||
|
where: { isDeleted: false },
|
||||||
include: { creator: true, metadataValues: true, storageKey: true },
|
include: { creator: true, metadataValues: true, storageKey: true },
|
||||||
take: 3,
|
take: 3,
|
||||||
orderBy: { sortIndex: 'asc' },
|
orderBy: { sortIndex: 'asc' },
|
||||||
@@ -801,6 +808,7 @@ export class AssetService {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
children: {
|
children: {
|
||||||
|
where: { isDeleted: false },
|
||||||
include: { creator: true, metadataValues: true, storageKey: true },
|
include: { creator: true, metadataValues: true, storageKey: true },
|
||||||
take: 3,
|
take: 3,
|
||||||
orderBy: { sortIndex: 'asc' },
|
orderBy: { sortIndex: 'asc' },
|
||||||
@@ -936,6 +944,7 @@ export class AssetService {
|
|||||||
metadataValues: true,
|
metadataValues: true,
|
||||||
storageKey: true,
|
storageKey: true,
|
||||||
children: {
|
children: {
|
||||||
|
where: { isDeleted: false },
|
||||||
include: { creator: true, metadataValues: true, storageKey: true },
|
include: { creator: true, metadataValues: true, storageKey: true },
|
||||||
take: 3,
|
take: 3,
|
||||||
orderBy: { sortIndex: 'asc' },
|
orderBy: { sortIndex: 'asc' },
|
||||||
@@ -943,6 +952,7 @@ export class AssetService {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
children: {
|
children: {
|
||||||
|
where: { isDeleted: false },
|
||||||
include: { creator: true, metadataValues: true, storageKey: true },
|
include: { creator: true, metadataValues: true, storageKey: true },
|
||||||
take: 3,
|
take: 3,
|
||||||
orderBy: { sortIndex: 'asc' },
|
orderBy: { sortIndex: 'asc' },
|
||||||
@@ -1641,6 +1651,7 @@ export class AssetService {
|
|||||||
folderForPreview.children
|
folderForPreview.children
|
||||||
) {
|
) {
|
||||||
for (const child of folderForPreview.children) {
|
for (const child of folderForPreview.children) {
|
||||||
|
if (child.isDeleted) continue
|
||||||
let previewAsset = child as Asset
|
let previewAsset = child as Asset
|
||||||
let mediaType = child.mediaType
|
let mediaType = child.mediaType
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { metadataService } from '@shumai/core/src/metadata/metadata'
|
|||||||
import { workflowService } from '@shumai/workflow-core'
|
import { workflowService } from '@shumai/workflow-core'
|
||||||
|
|
||||||
import { AssetType } from '@shumai/db'
|
import { AssetType } from '@shumai/db'
|
||||||
|
import { assetService } from '@shumai/core/src/asset/asset'
|
||||||
|
|
||||||
describe('SearchService', () => {
|
describe('SearchService', () => {
|
||||||
setupTestDbHooks()
|
setupTestDbHooks()
|
||||||
@@ -559,6 +560,57 @@ describe('SearchService', () => {
|
|||||||
expect(resultWithSymlink.data.find((a) => a.id === symlink.id)).toBeDefined()
|
expect(resultWithSymlink.data.find((a) => a.id === symlink.id)).toBeDefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('excludes soft-deleted (trashed) files from latestChildren when searching folders', async () => {
|
||||||
|
const { rootFolder } = await setupBasicAssets()
|
||||||
|
|
||||||
|
const subfolder = await prisma.asset.create({
|
||||||
|
data: {
|
||||||
|
name: 'subfolder',
|
||||||
|
type: AssetType.folder,
|
||||||
|
projectId: rootFolder.projectId,
|
||||||
|
parentId: rootFolder.id,
|
||||||
|
status: 'uploaded',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const childFile1 = await prisma.asset.create({
|
||||||
|
data: {
|
||||||
|
name: 'child1.txt',
|
||||||
|
type: AssetType.file,
|
||||||
|
projectId: rootFolder.projectId,
|
||||||
|
parentId: subfolder.id,
|
||||||
|
status: 'uploaded',
|
||||||
|
sortIndex: 'a0',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await prisma.asset.create({
|
||||||
|
data: {
|
||||||
|
name: 'child2.txt',
|
||||||
|
type: AssetType.file,
|
||||||
|
projectId: rootFolder.projectId,
|
||||||
|
parentId: subfolder.id,
|
||||||
|
status: 'uploaded',
|
||||||
|
sortIndex: 'a1',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await assetService.deleteAssets([childFile1.id])
|
||||||
|
|
||||||
|
const result = await searchService.search(rootFolder.id, {
|
||||||
|
recursively: false,
|
||||||
|
assetType: 'folder',
|
||||||
|
operator: 'AND',
|
||||||
|
conditions: [],
|
||||||
|
isSemantic: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
const searchedSubfolder = result.data.find((a) => a.id === subfolder.id)
|
||||||
|
expect(searchedSubfolder).toBeDefined()
|
||||||
|
|
||||||
|
expect(searchedSubfolder?.latestChildren?.length).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
describe('Semantic Search with multiple chunks and distance ordering', () => {
|
describe('Semantic Search with multiple chunks and distance ordering', () => {
|
||||||
it('returns multiple matching segments from the same asset and orders by distance', async () => {
|
it('returns multiple matching segments from the same asset and orders by distance', async () => {
|
||||||
const user = await prisma.user.create({
|
const user = await prisma.user.create({
|
||||||
|
|||||||
Reference in New Issue
Block a user