index products
Build and Deploy / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-07-07 21:38:02 +03:30
parent 4aaab104f9
commit d73a8c16e8
3 changed files with 13 additions and 0 deletions
@@ -53,6 +53,14 @@ const productSchema = new Schema<IProduct>(
{ timestamps: true, toJSON: { virtuals: true, versionKey: false }, _id: false, id: false }, { 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 () { productSchema.virtual("url").get(function () {
return `/product/SHP-${this._id}/${this.title_fa}`; 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 }, { 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) { productVariantSchema.pre("save", function (next) {
if (this.price) { if (this.price) {
if (this.price.retailPrice) { if (this.price.retailPrice) {
@@ -106,6 +106,7 @@ class ProductService {
{ title_fa: { $regex: q, $options: "i" } }, { title_fa: { $regex: q, $options: "i" } },
{ model: { $regex: q, $options: "i" } }, { model: { $regex: q, $options: "i" } },
], ],
deleted: false,
variants: { $elemMatch: { $exists: true } }, variants: { $elemMatch: { $exists: true } },
}, },
{ _id: 1, title_fa: 1, title_en: 1, imagesUrl: 1, model: 1, description: 1, variants: 1 }, { _id: 1, title_fa: 1, title_en: 1, imagesUrl: 1, model: 1, description: 1, variants: 1 },