Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 41 additions & 41 deletions packages/components/nodes/documentloaders/AAIDomains/AAIDomains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
return docs
}

async loadStream(

Check failure on line 289 in packages/components/nodes/documentloaders/AAIDomains/AAIDomains.ts

View workflow job for this annotation

GitHub Actions / build

Replace `⏎········nodeData:·INodeData,⏎········_:·string,⏎········__:·ICommonObject,⏎········onBatch:·(docs:·IDocument[])·=>·Promise<void>⏎····` with `nodeData:·INodeData,·_:·string,·__:·ICommonObject,·onBatch:·(docs:·IDocument[])·=>·Promise<void>`
nodeData: INodeData,
_: string,
__: ICommonObject,
Expand Down Expand Up @@ -442,6 +442,8 @@
let lastError: any = null
let shouldStopPagination = false

// Fetch page from Supabase with retry on transient errors only
let pageData: any[] | null = null
while (retryCount < maxRetries) {
try {
let selectFields: string
Expand Down Expand Up @@ -474,7 +476,7 @@
const requestedHeavy = heavyFields.filter((f) => requestedFields.has(f))
if (requestedHeavy.length > 0) {
console.warn(
`[AAIDomains] Warning: Fetching heavy JSONB fields: ${requestedHeavy.join(', ')}. This may impact performance.`

Check failure on line 479 in packages/components/nodes/documentloaders/AAIDomains/AAIDomains.ts

View workflow job for this annotation

GitHub Actions / build

Replace `',·'` with `⏎····································',·'⏎································`
)
}
} else {
Expand All @@ -498,7 +500,7 @@
`
}

let query = supabase

Check failure on line 503 in packages/components/nodes/documentloaders/AAIDomains/AAIDomains.ts

View workflow job for this annotation

GitHub Actions / build

Replace `⏎························.from('domains')⏎························.select(selectFields)⏎························.order('id',·{·ascending:·true·})⏎························` with `.from('domains').select(selectFields).order('id',·{·ascending:·true·})`
.from('domains')
.select(selectFields)
.order('id', { ascending: true })
Expand Down Expand Up @@ -542,61 +544,59 @@
domainsCount: data?.length || 0
})

if (!data || data.length === 0) {
console.info('[AAIDomains] No more data, stopping pagination')
shouldStopPagination = true
break
}

const domainsWithTags = (data as any[]).map((domain: any) => ({
...domain,
tags: domain.domain_tags?.map((dt: any) => dt.tags).filter(Boolean) || []
}))

let filteredDomains: any[] = domainsWithTags
if (this.includeTags.length > 0 || this.excludeTags.length > 0) {
filteredDomains = this.filterByTags(domainsWithTags)
}

fetchedDomainCount += filteredDomains.length

const pageDocs = filteredDomains.map((d: any) => this.createDocumentFromDomain(d))

const pageOutput = this.textSplitter
? await this.textSplitter.splitDocuments(pageDocs)
: pageDocs

await onPage(pageOutput)

// Advance cursor only after onPage callback succeeds
lastId = (data as any[])[data.length - 1].id
pageNum++

if (fetchedDomainCount >= this.limit || data.length < currentPageSize) {
shouldStopPagination = true
break
}

pageData = data
break
} catch (error: any) {
lastError = error
} catch (fetchError: any) {
lastError = fetchError
retryCount++

if (retryCount < maxRetries) {
const delayMs = Math.min(1000 * Math.pow(2, retryCount), 10000)
console.warn(
`[AAIDomains] Request failed (attempt ${retryCount}/${maxRetries}), retrying in ${delayMs}ms...`,
error.message
`[AAIDomains] Fetch failed (attempt ${retryCount}/${maxRetries}), retrying in ${delayMs}ms...`,
fetchError.message
)
await new Promise((resolve) => setTimeout(resolve, delayMs))
} else {
console.error(`[AAIDomains] All ${maxRetries} retry attempts failed`)
console.error(`[AAIDomains] All ${maxRetries} fetch attempts failed`)
throw lastError
}
}
}

if (shouldStopPagination || retryCount >= maxRetries) {
if (retryCount >= maxRetries) break

if (!pageData || pageData.length === 0) {
console.info('[AAIDomains] No more data, stopping pagination')
shouldStopPagination = true
} else {
// Process page and invoke callback — errors propagate up, not retried
const domainsWithTags = (pageData as any[]).map((domain: any) => ({
...domain,
tags: domain.domain_tags?.map((dt: any) => dt.tags).filter(Boolean) || []
}))

let filteredDomains: any[] = domainsWithTags
if (this.includeTags.length > 0 || this.excludeTags.length > 0) {
filteredDomains = this.filterByTags(domainsWithTags)
}

fetchedDomainCount += filteredDomains.length

const pageDocs = filteredDomains.map((d: any) => this.createDocumentFromDomain(d))
const pageOutput = this.textSplitter ? await this.textSplitter.splitDocuments(pageDocs) : pageDocs

await onPage(pageOutput)

lastId = (pageData as any[])[pageData.length - 1].id
pageNum++

if (fetchedDomainCount >= this.limit || pageData.length < currentPageSize) {
shouldStopPagination = true
}
}

if (shouldStopPagination) {
break
}

Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/services/documentstore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ const syncAndRefreshChunks = async (storeId: string, fileId: string, userId: str
const chunkRepository = appServer.AppDataSource.getRepository(DocumentStoreFileChunk)
const existingChunkIds = (
await chunkRepository.find({
select: { id: true },
where: {
docId: fileId,
userId,
Expand Down Expand Up @@ -1360,6 +1361,7 @@ const _saveChunksToStorage = async (
const chunkRepository = appDataSource.getRepository(DocumentStoreFileChunk)
const existingChunkIds = (
await chunkRepository.find({
select: { id: true },
where: {
docId: newLoaderId,
userId: data.userId,
Expand Down
Loading