Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isDateField to cache #968

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ public void putCollectionReference(String ref, CollectionReference col) {
putObject("collections", ref, col);
LOGGER.debug("Clearing field types of collection '" + ref + "' from cache");
this.instance.getReplicatedMap(ref).clear();
this.instance.getReplicatedMap(ref+"-datefield").clear();
}

@Override
public void removeCollectionReference(String ref) {
removeObject("collections", ref);
LOGGER.debug("Clearing field types of collection '" + ref + "' from cache");
this.instance.getReplicatedMap(ref).clear();
this.instance.getReplicatedMap(ref+"-datefield").clear();
}

@Override
Expand All @@ -68,6 +70,16 @@ public void putFieldType(String ref, String name, FieldType type) {
putObject(ref, name, type);
}

@Override
public Boolean getIsDateField(String ref, String name) {
return (Boolean) getObject(ref+"-datefield", name);
}

@Override
public void putIsDateField(String ref, String name, Boolean value) {
putObject(ref+"-datefield", name, value);
}

@Override
public void putMapping(String indexName, Map<String, Map<String, Object>> mapping) {
putObject("mappings", indexName, mapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ public void putCollectionReference(String ref, CollectionReference col) {
putObject("collections", ref, col);
LOGGER.debug("Clearing field types of collection '" + ref + "' from cache");
this.cache.computeIfAbsent(ref, k -> new SelfExpiringHashMap<>()).clear();
this.cache.computeIfAbsent(ref+"-datefield", k -> new SelfExpiringHashMap<>()).clear();
}

@Override
public void removeCollectionReference(String ref) {
removeObject("collections", ref);
LOGGER.debug("Clearing field types of collection '" + ref + "' from cache");
this.cache.computeIfAbsent(ref, k -> new SelfExpiringHashMap<>()).clear();
this.cache.computeIfAbsent(ref+"-datefield", k -> new SelfExpiringHashMap<>()).clear();
}

@Override
Expand All @@ -69,6 +71,16 @@ public void putFieldType(String ref, String name, FieldType type) {
putObject(ref, name, type);
}

@Override
public Boolean getIsDateField(String ref, String name) {
return (Boolean) getObject(ref+"-datefield", name);
}

@Override
public void putIsDateField(String ref, String name, Boolean value) {
putObject(ref+"-datefield", name, value);
}

@Override
public void putMapping(String indexName, Map<String, Map<String, Object>> mapping) {
putObject("mappings", indexName, mapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public FieldType getFieldType(String ref, String name) {
public void putFieldType(String ref, String name, FieldType type) {
}

@Override
public Boolean getIsDateField(String ref, String name) {
return null;
}

@Override
public void putIsDateField(String ref, String name, Boolean value) {

}

@Override
public void putMapping(String indexName, Map<String, Map<String, Object>> exists) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ protected void putCollectionReferenceWithDao(CollectionReference collectionRefer
}

@Override
public boolean isDateField(String field, String index) throws ArlasException {
return client.isDateField(field, index);
public boolean isDateField(String field, CollectionReference ref) throws ArlasException {
Boolean isDateField = cacheManager.getIsDateField(ref.collectionName, field);
if (isDateField == null) {
isDateField = client.isDateField(field, ref.params.indexName);
cacheManager.putIsDateField(ref.collectionName, field, isDateField);
}

return isDateField;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public interface CacheManager extends BaseCacheManager {
FieldType getFieldType(String ref, String name);
void putFieldType(String ref, String name, FieldType type);

Boolean getIsDateField(String ref, String name);
void putIsDateField(String ref, String name, Boolean value);

void putMapping(String indexName, Map<String, Map<String, Object>> exists);
Map<String, Map<String, Object>> getMapping(String indexName);
void removeMapping(String indexName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,10 @@ private FieldType getUnknownType(String parentField, String collectionName, bool
}
}

public boolean isDateField(String field, String index) throws ArlasException {
return getFieldType(field, index).isDateField();
public boolean isDateField(String field, CollectionReference ref) throws ArlasException {
return getFieldType(field, ref.params.indexName).isDateField();
}

public boolean isTextField(String field, String index) throws ArlasException {
return getFieldType(field, index).isTextField();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private boolean filterFHasDateQuery(Filter filter, CollectionReference collectio
try {
return collectionReferenceService.isDateField(
ParamsParser.getFieldFromFieldAliases(expression.field, collectionReference),
collectionReference.params.indexName);
collectionReference);
} catch (ArlasException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import io.arlas.commons.exceptions.ArlasException;
import io.arlas.commons.utils.StringUtil;
import io.arlas.server.core.app.ArlasServerConfiguration;
import io.arlas.server.core.managers.CollectionReferenceManager;
import io.arlas.server.core.model.CollectionReference;
import io.arlas.server.core.model.enumerations.AggregationTypeEnum;
Expand Down Expand Up @@ -154,7 +153,7 @@ public FluidSearchService include(String include) {
}

public boolean isDateField(String field) throws ArlasException {
return collectionReferenceManager.getCollectionReferenceService().isDateField(field, collectionReference.params.indexName);
return collectionReferenceManager.getCollectionReferenceService().isDateField(field, collectionReference);
}

public boolean isTextField(String field) throws ArlasException {
Expand Down
Loading