This commit is contained in:
@@ -53,6 +53,14 @@ const productSchema = new Schema<IProduct>(
|
||||
{ timestamps: true, toJSON: { virtuals: true, versionKey: false }, _id: false, id: false },
|
||||
);
|
||||
|
||||
productSchema.index({ status: 1, createdAt: -1 }, { partialFilterExpression: { deleted: false } });
|
||||
productSchema.index({ shop: 1, status: 1, createdAt: -1 }, { partialFilterExpression: { deleted: false } });
|
||||
productSchema.index({ category: 1, status: 1, createdAt: -1 }, { partialFilterExpression: { deleted: false } });
|
||||
productSchema.index({ brand: 1, status: 1, createdAt: -1 }, { partialFilterExpression: { deleted: false } });
|
||||
productSchema.index({ category: 1, brand: 1, status: 1 }, { partialFilterExpression: { deleted: false } });
|
||||
productSchema.index({ model: 1 }, { partialFilterExpression: { deleted: false } });
|
||||
productSchema.index({ tags: 1, status: 1 }, { partialFilterExpression: { deleted: false } });
|
||||
|
||||
productSchema.virtual("url").get(function () {
|
||||
return `/product/SHP-${this._id}/${this.title_fa}`;
|
||||
});
|
||||
|
||||
@@ -65,6 +65,10 @@ const productVariantSchema = new Schema<IProductVariant>(
|
||||
{ timestamps: true, toObject: { virtuals: true, versionKey: false }, toJSON: { virtuals: true, versionKey: false }, id: false },
|
||||
);
|
||||
|
||||
productVariantSchema.index({ product: 1, deleted: 1 });
|
||||
productVariantSchema.index({ shop: 1, product: 1, deleted: 1 });
|
||||
productVariantSchema.index({ market_status: 1, deleted: 1 });
|
||||
|
||||
productVariantSchema.pre("save", function (next) {
|
||||
if (this.price) {
|
||||
if (this.price.retailPrice) {
|
||||
|
||||
@@ -106,6 +106,7 @@ class ProductService {
|
||||
{ title_fa: { $regex: q, $options: "i" } },
|
||||
{ model: { $regex: q, $options: "i" } },
|
||||
],
|
||||
deleted: false,
|
||||
variants: { $elemMatch: { $exists: true } },
|
||||
},
|
||||
{ _id: 1, title_fa: 1, title_en: 1, imagesUrl: 1, model: 1, description: 1, variants: 1 },
|
||||
|
||||
Reference in New Issue
Block a user