mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-10-27 01:53:38 +00:00
improved duplicate repo handling
This commit is contained in:
@@ -306,8 +306,17 @@ router.post('/update', validateApiCredentials, [
|
|||||||
where: { hostId: host.id }
|
where: { hostId: host.id }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Process each repository
|
// Deduplicate repositories by URL+distribution+components to avoid constraint violations
|
||||||
|
const uniqueRepos = new Map();
|
||||||
for (const repoData of repositories) {
|
for (const repoData of repositories) {
|
||||||
|
const key = `${repoData.url}|${repoData.distribution}|${repoData.components}`;
|
||||||
|
if (!uniqueRepos.has(key)) {
|
||||||
|
uniqueRepos.set(key, repoData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process each unique repository
|
||||||
|
for (const repoData of uniqueRepos.values()) {
|
||||||
// Find or create repository
|
// Find or create repository
|
||||||
let repo = await tx.repository.findFirst({
|
let repo = await tx.repository.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@@ -332,8 +341,7 @@ router.post('/update', validateApiCredentials, [
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create host repository relationship (handle duplicates gracefully)
|
// Create host repository relationship
|
||||||
try {
|
|
||||||
await tx.hostRepository.create({
|
await tx.hostRepository.create({
|
||||||
data: {
|
data: {
|
||||||
hostId: host.id,
|
hostId: host.id,
|
||||||
@@ -342,24 +350,6 @@ router.post('/update', validateApiCredentials, [
|
|||||||
lastChecked: new Date()
|
lastChecked: new Date()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
|
||||||
// If it's a duplicate constraint error, update the existing record
|
|
||||||
if (error.code === 'P2002') {
|
|
||||||
await tx.hostRepository.updateMany({
|
|
||||||
where: {
|
|
||||||
hostId: host.id,
|
|
||||||
repositoryId: repo.id
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
isEnabled: repoData.isEnabled !== false,
|
|
||||||
lastChecked: new Date()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Re-throw other errors
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user