這裏是我的查詢:爲什麼cypher在neo4j管理面板中的查詢速度比在Rails應用程序中快?
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應用程序中,我使用Neo4j :: Session.query來進行此查詢。
你是對的。這是我發現的。我已經添加到每個查詢LIMIT語句,它的工作速度更快,大約1秒。 所以,現在我想要做這8個查詢,然後,通過updated_at字段排序,並且只取前10個。我該怎麼做? –
你在說什麼結果?假設您想在最終的最終結果集中獲得10個結果。如果您將這8個參數中的每一個設置爲10,您將以80個「臨時最終」結果結束。如果是我,第一選擇就是在你的ruby代碼中排序並獲得最新的10個。您介意將我的答案標記爲已接受嗎? – chrisfauerbach