MCPcopy Index your code
hub / github.com/simstudioai/sim / hardDeleteDocuments

Function hardDeleteDocuments

apps/sim/lib/knowledge/documents/service.ts:1970–2007  ·  view source on GitHub ↗
(
  documentIds: string[],
  requestId: string
)

Source from the content-addressed store, hash-verified

1968}
1969
1970export async function hardDeleteDocuments(
1971 documentIds: string[],
1972 requestId: string
1973): Promise<number> {
1974 const ids = [...new Set(documentIds)]
1975 if (ids.length === 0) {
1976 return 0
1977 }
1978
1979 const documentsToDelete = await db
1980 .select({
1981 id: document.id,
1982 fileUrl: document.fileUrl,
1983 workspaceId: knowledgeBase.workspaceId,
1984 })
1985 .from(document)
1986 .innerJoin(knowledgeBase, eq(document.knowledgeBaseId, knowledgeBase.id))
1987 .where(inArray(document.id, ids))
1988
1989 if (documentsToDelete.length === 0) {
1990 return 0
1991 }
1992
1993 const existingIds = documentsToDelete.map((doc) => doc.id)
1994
1995 await db.transaction(async (tx) => {
1996 await tx.delete(embedding).where(inArray(embedding.documentId, existingIds))
1997 await tx.delete(document).where(inArray(document.id, existingIds))
1998 })
1999
2000 await deleteDocumentStorageFiles(documentsToDelete, requestId)
2001
2002 logger.info(`[${requestId}] Hard deleted ${existingIds.length} documents`, {
2003 documentIds: existingIds,
2004 })
2005
2006 return existingIds.length
2007}
2008
2009export async function deleteDocument(
2010 documentId: string,

Callers 2

executeSyncFunction · 0.90

Calls 4

infoMethod · 0.80
deleteMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected