【发布时间】:2019-06-25 10:57:01
【问题描述】:
我有一个 Cypher 查询,用于获取实时用户供稿。用户有朋友,用户也关注其他人。查询返回正确的结果,但返回结果需要较长时间(11395 ms)。
我已经在节点的以下属性上创建了索引 用户(userId、IsActive、FeaturedUser) 提要(访问范围)
我还试图找出我们是否可以在关系上创建索引,但没有任何运气。
MATCH (u:User { SpFeaturedUser: true })<-[:CREATED_BY]-(fe)-[:FEED_TYPE]->(:ServiceType{Id: 13})
WITH fe
ORDER BY fe.UpdatedUTCDateTime DESC
SKIP 0
LIMIT 100
OPTIONAL MATCH (fe)-[:CREATED_BY]->(u:User)
OPTIONAL MATCH (fe)-[:FEED_TYPE]->(st:ServiceType)
OPTIONAL MATCH (fe)-[endrs:ENDORSED]->(p:Place)
OPTIONAL MATCH (p:Place)-[placeImage:RELATED_IMAGE]->(pImg:Image)
OPTIONAL MATCH(fe)< -[likes: LIKES] - ()
OPTIONAL MATCH(fe)< -[cmts: COMMENT_ON_FEED] - (c)
OPTIONAL MATCH (m:Mentions)-[:MENTIONED_IN]->(fe)
OPTIONAL MATCH (fe)-[:RELATED_IMAGE]->(img:Image)
OPTIONAL MATCH (fe)-[:RELATED_SERVICE_URL]->(su)
WITH {
Description: fe.Description,
DescriptionEncoded: fe.DescriptionEncoded,
EndorsementType: fe.PostType,
CreatedUTCDateTime: fe.CreatedDateTime,
UpdatedUTCDateTime: fe.UpdatedDateTime,
StartDate: fe.StartDate,
EndDate: fe.EndDate,
AccessScope: fe.AccessScope,
Rating: fe.Rating,
EndorsementId: fe.ServiceId,
ServiceTypeId: st.Id,
LikeCount: Count(distinct(likes)),
IsLiked: EXISTS((fe) < -[:LIKES] - (: User{ UserId: "4F97D90E-922C-4C44-8F68-8311C60D76D9"}) ),
CommentsCount: Count(distinct(cmts)),
LastActivity: {
en: fe.Activity,
da: fe.DanishActivity
},
User: {
UserId: u.UserId,
FirstName: u.FirstName,
FileName: u.FileName,
SocialMediaAttribution: {
}
},
Endorsement_Mentions: CASE WHEN m IS NOT NULL THEN Collect(distinct {
Name: m.Name,
Type: m.TagType,
PlaceHolder: m.Placeholder,
TagID: m.TagId
}) ELSE [] END ,
Endorsement_Image: CASE WHEN img IS NOT NULL THEN Collect(distinct {
ImageUrl: img.ImageUrl,
Width: img.Width,
Height: img.Height,
Extension: img.Extension,
CreatedUTCDateTime: img.CreatedUTCDateTime
}) ELSE [] END,
URLPreviews: CASE WHEN su IS NOT NULL THEN Collect(distinct {
Title : su.UrlTitle ,
Description : su.UrlDescription ,
ImageURL : su.PreviewImage ,
URL : su.Url ,
Width : su.Width ,
Height : su.Height ,
Extension : su.Extension ,
IsVideoUrl : su.IsVideoUrl ,
VideoStreamUrl : su.VideoStreamUrl,
VideoType : su.VideoType
}) ELSE [] END,
Object: {
ObjectId: p.ObjectId,
Name: p.ObjectName,
IsFollowed: EXISTS((fe)-[:ENDORSED]->()<-[:FOLLOW]-({UserId : "4F97D90E-922C-4C44-8F68-8311C60D76D9"})),
AverageRating: {
Count: p.ObjectAvgRating
},
EndorsementCount: Count(distinct(endrs)),
Object_Image: CASE WHEN pImg IS NOT NULL THEN
Collect(distinct {
ImageUrl: pImg.ImageUrl,
Width: pImg.Width,
Height: pImg.Height,
Extension: pImg.Extension,
CreatedUTCDateTime: pImg.CreatedUTCDateTime
}) ELSE [] END,
Category: {
CategoryId: p.CategoryId
},
Country: {
ShowBarometer: false
}
}
} as Feed
RETURN DISTINCT(Feed)
ORDER BY Feed.UpdatedUTCDateTime DESC
预期结果是,该查询应该运行得足够快,可以在 2-3 秒内返回结果,因为其他查询已经在运行。
【问题讨论】:
-
有这些
OPTIONAL MATCH子句有充分的理由吗?你似乎没有使用他们可能找到的任何东西。还有为什么要生成空的SocialMediaAttribution地图?