fix(property): optimize save performance, fix 2dsphere index error and make search indexing non-blocking
deploy-chabokan / deploy (push) Canceled after 0s

This commit is contained in:
2026-08-19 07:46:08 +03:30
parent 30ea3aed84
commit e63ac1ddf4
7 changed files with 193 additions and 82 deletions
+39 -37
View File
@@ -174,50 +174,52 @@ const moveFromTempToMain = async (files, targetBucket) => {
return []
}
const { ensureBucketsExist, minioClient } = require('../../utils/upload/bucket')
await ensureBucketsExist([tempBucket, targetBucket]).catch(() => {})
const { minioClient } = require('../../utils/upload/bucket')
const updatedUrls = []
const updatedUrls = await Promise.all(
files.map(async (item) => {
const rawStr = typeof item === 'object' && item !== null ? (item.url || item.fileName || item.name || '') : String(item || '')
const fileName = getLastUrlSegment(rawStr)
for (const item of files) {
const rawStr = typeof item === 'object' && item !== null ? (item.url || item.fileName || item.name || '') : String(item || '')
const fileName = getLastUrlSegment(rawStr)
if (!fileName) {
continue
}
try {
// Check if object exists in temp bucket
const existsInTemp = await minioClient.statObject(tempBucket, fileName).then(() => true).catch(() => false)
if (existsInTemp) {
// Copy object from temp to targetBucket
await copyObject(targetBucket, fileName, `/${tempBucket}/${fileName}`)
// Remove from temp bucket
await removeObject(tempBucket, fileName)
// Update File record in database if exists
await File.findOneAndUpdate({ fileName }, { bucketName: targetBucket }, null).catch(() => {})
if (!fileName) {
return null
}
// Construct new URL for targetBucket
const protocol = process.env.AWS_USE_SSL === 'true' ? 'https://' : 'http://'
const endpoint = process.env.AWS_ENDPOINT || 'localhost'
const hostPort = (endpoint.includes(':') || !process.env.AWS_PORT) ? endpoint : `${endpoint}:${process.env.AWS_PORT}`
const fullHost = hostPort.startsWith('http://') || hostPort.startsWith('https://') ? hostPort : `${protocol}${hostPort}`
const newUrl = `${fullHost.replace(/\/$/, '')}/${targetBucket}/${fileName}`
try {
// Check if object exists in temp bucket
const existsInTemp = await minioClient.statObject(tempBucket, fileName).then(() => true).catch(() => false)
if (existsInTemp) {
// Copy object from temp to targetBucket
await copyObject(targetBucket, fileName, `/${tempBucket}/${fileName}`).catch((err) => {
console.error(`Failed to copy object "${fileName}" to "${targetBucket}":`, err.message)
})
// Remove from temp bucket
await removeObject(tempBucket, fileName).catch((err) => {
console.error(`Failed to remove object "${fileName}" from "${tempBucket}":`, err.message)
})
// Update File record in database if exists
await File.findOneAndUpdate({ fileName }, { bucketName: targetBucket }, null).catch(() => {})
}
updatedUrls.push(newUrl)
} catch (err) {
console.error(`Failed to move file "${fileName}" from ${tempBucket} to ${targetBucket}:`, err)
if (rawStr.includes(`/${tempBucket}/`)) {
updatedUrls.push(rawStr.replace(`/${tempBucket}/`, `/${targetBucket}/`))
} else {
updatedUrls.push(rawStr)
// Construct new URL for targetBucket
const protocol = process.env.AWS_USE_SSL === 'true' ? 'https://' : 'http://'
const endpoint = process.env.AWS_ENDPOINT || 'localhost'
const hostPort = (endpoint.includes(':') || !process.env.AWS_PORT) ? endpoint : `${endpoint}:${process.env.AWS_PORT}`
const fullHost = hostPort.startsWith('http://') || hostPort.startsWith('https://') ? hostPort : `${protocol}${hostPort}`
const newUrl = `${fullHost.replace(/\/$/, '')}/${targetBucket}/${fileName}`
return newUrl
} catch (err) {
console.error(`Failed to move file "${fileName}" from ${tempBucket} to ${targetBucket}:`, err.message)
if (rawStr.includes(`/${tempBucket}/`)) {
return rawStr.replace(`/${tempBucket}/`, `/${targetBucket}/`)
}
return rawStr
}
}
}
})
)
return updatedUrls
return updatedUrls.filter(Boolean)
}
const getImage = async (bucketName, fileName) => {