fix(property): optimize save performance, fix 2dsphere index error and make search indexing non-blocking
deploy-chabokan / deploy (push) Canceled after 0s
deploy-chabokan / deploy (push) Canceled after 0s
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user