简体   繁体   English

HybridRelations laravel mongo 真的很慢

[英]HybridRelations laravel mongo is really slow

Used HybridRelations to store user notifications in mongoDB instead of mysql and imported 3million records and now user->notifications()->take(5)->get() or user->notifications()->paginate(5) takes over 30 seconds.使用 HybridRelations 将用户通知存储在 mongoDB 而不是 mysql 中并导入了 300 万条记录,现在 user->notifications()->take(5)->get() 或 user->notifications()->paginate(5) 超过 30秒。 any idea how to speed it up?知道如何加快速度吗? on mysql with same amount of records it took 200 milliseconds.在具有相同记录数量的 mysql 上,它花费了 200 毫秒。

notificaiton model has user_id and description and priority and read flag and user_id is set as an index.通知模型具有 user_id 和 description 和优先级以及读取标志,并且 user_id 被设置为索引。

Maybe this suggestion can help you.也许这个建议可以帮到你。

When use user->notifications() means the query like that当使用user->notifications()意味着这样的查询

db.notificaiton.find( {"user_id": <?> } )

That will get all record by user_id.这将通过 user_id 获取所有记录。

You can dump the user->notifications() and check.您可以转储user->notifications()并检查。 That should be Collection type and contains more than 5 records.那应该是Collection类型并且包含超过 5 条记录。

The solution is this .解决办法是这样的 You can write specific method to ensure what your mongo query expression.您可以编写特定的方法来确保您的 mongo 查询表达式。


问题是您排序的列应该是索引以及您使用 where 子句的列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM