为什么密码查询在neo4j管理面板中比在Rails应用程序中更快?

时间:2017-07-31 05:06:32

标签: ruby-on-rails neo4j

这是我的问题:

MATCH (me:User{username: 'username'})-[:user_posted_post|user_share_post|post_in_gr|post_in_page]->(posts1:Post) WHERE posts1.hidden_id IS NULL AND NOT (me)-[:user_hide_post]-(posts1) return posts1 as posts
      UNION
      MATCH (me:User{username: 'username'})-[{subscribe: '1'}]-()-[:post_in_gr]-(posts3:Post)-[:user_posted_post|user_share_post]-(User{status:'active'}) WHERE posts3.access IN ['everybody', 'friend'] AND posts3.hidden_id IS NULL AND NOT (me)-[:user_hide_post]-(posts3) RETURN posts3 as posts
      UNION
      MATCH (me:User{username: 'username'})-[{subscribe: '1'}]-()-[:post_in_page]-(posts4:Post)-[:user_posted_post|user_share_post]-({status:'active'}) WHERE posts4.access IN ['everybody', 'friend'] AND posts4.hidden_id IS NULL AND NOT (me)-[:user_hide_post]-(posts4) RETURN posts4 as posts
      UNION
      MATCH (me:User{username: 'username'})-[:user_author_page]-()-[:post_in_page]-(posts5:Post)-[:user_posted_post|user_share_post]-({status:'active'}) WHERE posts5.access IN ['everybody', 'friend'] AND posts5.hidden_id IS NULL AND NOT (me)-[:user_hide_post]-(posts5) RETURN posts5 as posts
      UNION
      MATCH (me:User{username: 'username'})-[{subscribe: '1'}]-({status:'active'})-[:user_posted_post|user_share_post]-(posts6:Post{system_type: 'page'}) WHERE posts6.access IN ['everybody', 'friend'] AND posts6.hidden_id IS NULL AND NOT (me)-[:user_hide_post]-(posts6) RETURN posts6 as posts
      UNION
      MATCH (me:User{username: 'username'})-[{subscribe: '1'}]-({status:'active'})-[:user_posted_post|user_share_post]-(posts7:Post)  WHERE posts7.access IN ['everybody', 'friend'] AND NOT (posts7)-[:post_in_gr]-() AND NOT (posts7)-[:post_in_page]-() AND posts7.hidden_id IS NULL AND NOT (me)-[:user_hide_post]-(posts7) RETURN posts7 as posts
      UNION 
      MATCH (me:User{username: 'username'})-[:user_create_com]-()-[:com_in_post]-(posts8:Post) WHERE  posts8.access IN ['everybody', 'friend'] AND posts8.hidden_id IS NULL AND NOT (me)-[:user_hide_post]-(posts8) RETURN posts8 as posts
      UNION
      MATCH (me:User{username: 'username'})-[:user_can_see_post|user_posted_post]-(posts9:Post) WHERE posts9.access = 'custom' AND posts9.hidden_id IS NULL AND NOT (me)-[:user_hide_post]-(posts9) RETURN posts9 as posts").to_a

此查询在管理面板中大约需要1300毫秒,但rails应用中的相同查询需要超过4000毫秒。

在rails app中,我使用Neo4j :: Session.query进行此查询。

1 个答案:

答案 0 :(得分:0)

与Java相比,我使用Python也有类似的问题。不幸的是,我不能专门谈论Rails集成,但是,我可以提供一些关于性能的想法:

1)检查查询的配置文件。请记住,您实际上正在执行8个唯一查询 2)查看具有多个关系的查询和未标记的节点

例如:

MATCH(me:User {username:'username'}) - [:user_author_page] - () - [:post_in_page] - (posts5:Post) - [:user_posted_post | user_share_post] - ({status:'active' })where posts5.access IN ['everybody','friend']和posts5.hidden_​​id IS NULL AND NOT(me) - [:user_hide_post] - (posts5)RETURN posts5 as posts

3)使用其他驱动程序尝试使用其他语言的相同查询。也许它的Ruby驱动程序很臭?与Java

相比,python花了30-40倍的时间将节点转换为本机python对象

克里斯。

https://fauie.com