node.js - FeatherJs (express) 可扩展性问题
问题描述
我正在制作一个汽车市场,在解决字段时遇到了可扩展性问题。
我正在使用 MongoDb 和 FeatherJs(基于 Express)。我有以下 MongoDb 文档:listings、vehicles、vehicle_extras、users、users_profile、locations
在列表的正文中,我正在存储
featuredUntil: { type: Date, default: null },
locationId: {
type: mongooseClient.Schema.Types.ObjectId,
ref: "locations",
required: true,
},
userId: {
type: mongooseClient.Schema.Types.ObjectId,
ref: "users",
required: true,
},
vehicleId: {
type: mongooseClient.Schema.Types.ObjectId,
ref: "vehicles",
required: true,
},
... and more
},
现在在我的 Feather 列表挂钩(https://docs.feathersjs.com/api/hooks.html)中,我正在做一个
after: {
all: [
fastJoin(vehicleResolver),
fastJoin(userResolver),
fastJoin(locationResolver),
],
有一个看起来像的解析器
const vehicleResolver = {
joins: {
vehicle: () => async (instance, context) => {
try {
if (instance && instance.vehicleId) {
instance.vehicle = await context.app
.service("vehicles")
.get(instance.vehicleId);
}
return context;
} catch (e) {
return context;
}
},
},
};
现在这一切都很有趣和游戏,但我的车辆正在额外解析车辆、图像等,并且请求 $limit=50 列表需要将近 7 秒。($limit=10 大约需要 1 秒)
如何使用 MongoDb 正确处理这个问题?我应该将所有(或更多数据)存储在单个文档中吗?
解决方案
推荐阅读
- java - 使用多线程设置 Java 对象的两个或多个变量
- python - Azure Python App Function 不再在本地运行 - 模块“azure.functions_worker”没有属性“start_async”
- javascript - 如何访问 JSON 文档中的子元素
- python-3.x - Selenium - execute_async_script 中未提供回调
- excel - 根据单元格值更改 ActiveX 控件文本框颜色
- ruby-on-rails - 无法设置 rails 数据库
- ios - InputAccessoryView 正在浏览导航栏
- java - Android 使进度条背景颜色不透明度 100%
- recursion - 汇编中的阿克曼函数 - 陷入无限递归
- dialogflow-es - 在 Dialogflow 中创建的 Google Assistant 应用程序的密码