我正在使用neo4j
版本1.8.1
和spring-data-neo4j
版本2.2.0. RELEASE
。
问题在于neo4j的节省速度。我不明白为什么会这样。该节点持续进入db约30秒。这是我的模特课。
@NodeEntity
public class GraphUser {
public static final String FACEBOOK_FRIEND = "FACEBOOK_FRIEND";
public static final String TWITTER_FOLLOW = "TWITTER_FOLLOW";
public static final String CONTACT = "CONTACT";
public static final String KNOWS = "KNOWS";
public static final String BLOCKED = "BLOCKED";
public static final String FAVORITE = "FAVORITE";
@GraphId
private Long id;
@Indexed(unique = true, indexType = IndexType.FULLTEXT, indexName = "userIdIndex")
private String userId;
@Indexed(indexType = IndexType.FULLTEXT, indexName = "facebookIdIndex")
private String facebookId;
@Indexed(indexType = IndexType.FULLTEXT, indexName = "twitterIdIndex")
private String twitterId;
@Indexed(indexType = IndexType.FULLTEXT, indexName = "emailIndex")
private String email;
@Indexed(indexType = IndexType.FULLTEXT, indexName = "phoneNumberIndex")
private String phoneNumber;
private String knowsLevel;
@RelatedTo(type = FACEBOOK_FRIEND, direction = Direction.BOTH)
@Fetch
private Set<GraphUser> facebookRelations = new HashSet<GraphUser>();
@RelatedTo(type = TWITTER_FOLLOW, direction = Direction.OUTGOING)
@Fetch
private Set<GraphUser> twitterRelations = new HashSet<GraphUser>();
@RelatedTo(type = CONTACT, direction = Direction.OUTGOING)
@Fetch
private Set<GraphUser> contacts = new HashSet<GraphUser>();
@RelatedTo(type = KNOWS, direction = Direction.OUTGOING)
@Fetch
private Set<GraphUser> knows = new HashSet<GraphUser>();
@RelatedTo(type = BLOCKED, direction = Direction.OUTGOING)
@Fetch
private Set<GraphUser> blocks = new HashSet<GraphUser>();
@RelatedTo(type = FAVORITE, direction = Direction.OUTGOING)
@Fetch
private Set<GraphUser> favorites = new HashSet<GraphUser>();
@Query(value = "start user=node({self}), user2=node(*), matchedUser=node(*) " +
"where has(user2.userId) and has(matchedUser.userId) and has(user.knowsLevel) and has(user2.knowsLevel) and has(matchedUser.knowsLevel) " +
"and " +
"user.userId<>matchedUser.userId " +
"and " +
"(" +
"(user.knowsLevel='ALL' and (matchedUser.knowsLevel='ALL' or (user)<-[:KNOWS]-(matchedUser) or ((user)<-[:KNOWS]-(user2)<-[:KNOWS]-(matchedUser) and matchedUser.knowsLevel='SECOND'))) " +
"or " +
"(user.knowsLevel='SECOND' and ((user)-[:KNOWS]->(matchedUser) or (user)-[:KNOWS]->(user2)-[:KNOWS]->(matchedUser)) and (matchedUser.knowsLevel='ALL' or (user)<-[:KNOWS]-(matchedUser) or ((user)<-[:KNOWS]-(user2)<-[:KNOWS]-(matchedUser) and matchedUser.knowsLevel='SECOND'))) " +
"or " +
"(user.knowsLevel='FIRST' and (user)-[:KNOWS]->(matchedUser) and (matchedUser.knowsLevel='ALL' or (user)<-[:KNOWS]-(matchedUser) or ((user)<-[:KNOWS]-(user2)<-[:KNOWS]-(matchedUser) and matchedUser.knowsLevel='SECOND')))" +
") " +
"return matchedUser")
@Fetch
private Iterable<GraphUser> matchedUsers;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getFacebookId() {
return facebookId;
}
public void setFacebookId(String facebookId) {
this.facebookId = facebookId;
}
public String getTwitterId() {
return twitterId;
}
public void setTwitterId(String twitterId) {
this.twitterId = twitterId;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getKnowsLevel() {
return knowsLevel;
}
public void setKnowsLevel(String knowsLevel) {
this.knowsLevel = knowsLevel;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public Set<GraphUser> getFacebookRelations() {
return facebookRelations;
}
public void setFacebookRelations(Set<GraphUser> facebookRelations) {
this.facebookRelations = facebookRelations;
}
public Set<GraphUser> getTwitterRelations() {
return twitterRelations;
}
public void setTwitterRelations(Set<GraphUser> twitterRelations) {
this.twitterRelations = twitterRelations;
}
public Set<GraphUser> getContacts() {
return contacts;
}
public void setContacts(Set<GraphUser> contacts) {
this.contacts = contacts;
}
public Set<GraphUser> getKnows() {
return knows;
}
public void setKnows(Set<GraphUser> knows) {
this.knows = knows;
}
public Set<GraphUser> getBlocks() {
return blocks;
}
public void setBlocks(Set<GraphUser> blocks) {
this.blocks = blocks;
}
public Set<GraphUser> getFavorites() {
return favorites;
}
public void setFavorites(Set<GraphUser> favorites) {
this.favorites = favorites;
}
}
我可能缺少什么?
谢谢。
答案 0 :(得分:0)
两名嫌犯
我建议您首先删除@Fetch然后删除@Index,然后查看是否可以提高性能。你还在进行批量插入吗?