Skip to content

Commit

Permalink
added indexing on various fields to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
HetavShah committed Jun 26, 2023
1 parent 9386ff0 commit f2575fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions orders/src/models/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ const orderSchema = new mongoose.Schema<OrderDoc,OrderModel>(
qty: { type: Number, required: true },
price: { type: Number, required: true },
productId: { type: String, required: true },
sellerId:{type:String,required:true},
sellerId:{type:String,required:true,index:{
type:'hashed'
}},
product: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product',
Expand Down Expand Up @@ -154,7 +156,9 @@ const orderSchema = new mongoose.Schema<OrderDoc,OrderModel>(
timestamps: true,
}
);

orderSchema.index({
userId:'hashed'
})
orderSchema.set('versionKey', 'version');

// @ts-ignore
Expand Down
7 changes: 6 additions & 1 deletion products/src/models/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ const productSchema = new mongoose.Schema(
timestamps: true,
}
);

productSchema.index({
title: 'text',
})
productSchema.index({
userId:'hashed'
})
productSchema.set('versionKey', 'version');

productSchema.plugin(updateIfCurrentPlugin);
Expand Down

0 comments on commit f2575fc

Please sign in to comment.