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
+18 -1
View File
@@ -73,6 +73,7 @@ const propertySchema = new mongoose.Schema(
ownershipDocs: String,
// Property Specifications (مشخصات ملک)
area: Number, // مساحت عرصه (متر مربع)
registrationPlate: String,
mainNumber: String,
subNumber: String,
@@ -115,6 +116,22 @@ const propertySchema = new mongoose.Schema(
propertySchema.plugin(AutoIncrement, { inc_field: 'propertyCode' })
// Pre-validate hook: sanitize location for 2dsphere index
propertySchema.pre('validate', function (next) {
if (
!this.location ||
!Array.isArray(this.location.coordinates) ||
this.location.coordinates.length !== 2 ||
isNaN(this.location.coordinates[0]) ||
isNaN(this.location.coordinates[1])
) {
this.location = undefined
} else {
this.location.type = 'Point'
}
next()
})
propertySchema.methods.getDocumentsSignedUrls = function () {
return getMultipleSignedUrls(this.documentUrls, 'documents')
}
@@ -123,7 +140,7 @@ propertySchema.methods.getMainImagedSignedUrl = function () {
return getMultipleSignedUrls(this.mainImageUrls, 'properties')
}
propertySchema.index({ location: '2dsphere' })
propertySchema.index({ location: '2dsphere' }, { sparse: true })
const Property = mongoose.model('Property', propertySchema)