DATAGRAPH-548 - Fix Caching of IndexInfo for RestIndex
This commit is contained in:
@@ -534,6 +534,7 @@ public class RestAPICypherImpl implements RestAPI {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends PropertyContainer> RestIndex<T> createIndex(Class<T> type, String indexName, Map<String, String> config) {
|
||||
resetIndex(type);
|
||||
if (Node.class.isAssignableFrom(type)) {
|
||||
return (RestIndex<T>) index().forNodes( indexName, config);
|
||||
}
|
||||
@@ -543,6 +544,11 @@ public class RestAPICypherImpl implements RestAPI {
|
||||
throw new IllegalArgumentException("Required Node or Relationship types to create index, got " + type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetIndex(Class type) {
|
||||
restAPI.resetIndex(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
restAPI.close();
|
||||
|
||||
@@ -243,11 +243,23 @@ public class RestAPIImpl implements RestAPI {
|
||||
data.put("name",indexName);
|
||||
data.put("config",config);
|
||||
restRequest.post("index/" + type, data);
|
||||
IndexInfo indexInfo = indexInfos.get(type);
|
||||
if (indexInfo!=null) indexInfo.setExpired();
|
||||
}
|
||||
|
||||
public void resetIndex(Class type) {
|
||||
if (Node.class.isAssignableFrom(type)) {
|
||||
indexInfo(RestIndexManager.NODE).setExpired();
|
||||
}
|
||||
if (Relationship.class.isAssignableFrom(type)) {
|
||||
indexInfo(RestIndexManager.RELATIONSHIP).setExpired();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends PropertyContainer> RestIndex<T> createIndex(Class<T> type, String indexName, Map<String, String> config) {
|
||||
resetIndex(type);
|
||||
if (Node.class.isAssignableFrom(type)) {
|
||||
return (RestIndex<T>) index().forNodes( indexName, config);
|
||||
}
|
||||
@@ -576,7 +588,7 @@ public class RestAPIImpl implements RestAPI {
|
||||
public IndexInfo indexInfo(final String indexType) {
|
||||
IndexInfo indexInfo = indexInfos.get(indexType);
|
||||
if (indexInfo != null && !indexInfo.isExpired()) {
|
||||
// return indexInfo;
|
||||
return indexInfo;
|
||||
}
|
||||
RequestResult response = restRequest.get("index/" + encode(indexType));
|
||||
indexInfo = new RetrievedIndexInfo(response);
|
||||
@@ -619,12 +631,14 @@ public class RestAPIImpl implements RestAPI {
|
||||
@Override
|
||||
public void delete(RestIndex index) {
|
||||
deleteIndex(indexPath(index, null, null));
|
||||
resetIndex(index.getEntityType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends PropertyContainer> void removeFromIndex(RestIndex index, T entity, String key, Object value) {
|
||||
String indexPath = indexPath(index, key, value);
|
||||
deleteIndex(indexPath(indexPath, entity));
|
||||
resetIndex(index.getEntityType());
|
||||
}
|
||||
|
||||
protected <T extends PropertyContainer> String indexPath(String indexPath, T restEntity) {
|
||||
@@ -635,6 +649,7 @@ public class RestAPIImpl implements RestAPI {
|
||||
public <T extends PropertyContainer> void removeFromIndex(RestIndex index, T entity, String key) {
|
||||
String indexPath = indexPath(index, key, null);
|
||||
deleteIndex(indexPath(indexPath, entity));
|
||||
resetIndex(index.getEntityType());
|
||||
}
|
||||
|
||||
private String indexPath(RestIndex index, String key, Object value) {
|
||||
@@ -644,6 +659,7 @@ public class RestAPIImpl implements RestAPI {
|
||||
@Override
|
||||
public <T extends PropertyContainer> void removeFromIndex(RestIndex index, T entity) {
|
||||
deleteIndex(indexPath(indexPath(index, null, null), entity));
|
||||
resetIndex(index.getEntityType());
|
||||
}
|
||||
|
||||
public String uniqueIndexPath(RestIndex index) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.neo4j.rest.graphdb;
|
||||
|
||||
import org.neo4j.graphdb.PropertyContainer;
|
||||
import org.neo4j.rest.graphdb.converter.RestEntityExtractor;
|
||||
import org.neo4j.rest.graphdb.entity.RestEntity;
|
||||
import org.neo4j.rest.graphdb.entity.RestNode;
|
||||
@@ -22,6 +23,8 @@ public interface RestAPIInternal {
|
||||
// todo add to cache or update data in cache
|
||||
RestEntity createRestEntity(Map data);
|
||||
|
||||
void resetIndex(Class type);
|
||||
|
||||
public enum Load {
|
||||
FromCache,
|
||||
FromServer,
|
||||
|
||||
@@ -35,4 +35,6 @@ public interface IndexInfo {
|
||||
Map<String, String> getConfig(String name);
|
||||
|
||||
boolean isExpired();
|
||||
|
||||
void setExpired();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public abstract class RestIndex<T extends PropertyContainer> implements Index<T>
|
||||
return new RestGraphDatabase(restApi);
|
||||
}
|
||||
|
||||
private String getTypeName() {
|
||||
public String getTypeName() {
|
||||
return getEntityType().getSimpleName().toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
@@ -82,4 +82,10 @@ public class RetrievedIndexInfo implements IndexInfo {
|
||||
public boolean isExpired() {
|
||||
return System.currentTimeMillis() > expired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpired() {
|
||||
this.expired = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user