Skip to content

Commit 112920b

Browse files
Update GitHub import to use batch endpoint for better performance
1 parent 9036a13 commit 112920b

1 file changed

Lines changed: 23 additions & 22 deletions

File tree

components/github-import.tsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -166,30 +166,31 @@ export function GitHubImport({ onImport, onClose }: GitHubImportProps) {
166166
// Fetch all files recursively
167167
const allFiles = await fetchAllFiles(owner, repoName, rootData.contents || [])
168168

169-
// Save files to workspace
170-
let importedCount = 0
171-
for (const file of allFiles) {
172-
try {
173-
const response = await fetch('/api/files', {
174-
method: 'POST',
175-
headers: {
176-
'Content-Type': 'application/json',
177-
},
178-
body: JSON.stringify({
179-
path: `${repo.name}/${file.path}`,
180-
isDirectory: false,
181-
content: file.content,
182-
}),
183-
})
184-
185-
if (response.ok) {
186-
importedCount++
187-
}
188-
} catch (error) {
189-
console.warn(`Failed to import file ${file.path}:`, error)
190-
}
169+
// Save files to workspace using batch endpoint
170+
const filesToImport = allFiles.map(file => ({
171+
path: `${repo.name}/${file.path}`,
172+
content: file.content,
173+
isDirectory: false
174+
}))
175+
176+
const response = await fetch('/api/files/batch', {
177+
method: 'POST',
178+
headers: {
179+
'Content-Type': 'application/json',
180+
},
181+
body: JSON.stringify({
182+
files: filesToImport
183+
}),
184+
})
185+
186+
if (!response.ok) {
187+
const errorData = await response.json()
188+
throw new Error(errorData.error || 'Failed to import files')
191189
}
192190

191+
const result = await response.json()
192+
const importedCount = result.imported || 0
193+
193194
toast({
194195
title: "Success",
195196
description: `Successfully imported ${repo.name} with ${importedCount} files.`,

0 commit comments

Comments
 (0)