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

cleanup: Add no-internalModels-flag variants to methods used by GMS's #475

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -1075,6 +1075,24 @@ protected Map<URN, VALUE> getInternal(@Nonnull Collection<URN> urns,
: toValue(newSnapshot(e.getKey(), e.getValue()))));
}

/**
* Same as the above but doesn't require the callee to provide the 'isInternalModelsEnabled' flag.
*
* @param urns collection of urns
* @param aspectClasses set of aspect classes
* @return All {@link VALUE} objects keyed by {@link URN} obtained from DB
*/
@Nonnull
protected Map<URN, VALUE> getInternal(@Nonnull Collection<URN> urns,
@Nonnull Set<Class<? extends RecordTemplate>> aspectClasses) {
final boolean isInternalModelsEnabled = getResourceLix().testGetAll(_urnClass.getSimpleName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the getResourceList().testGetAll() gives low granular lix control on getAll method. Putting it inside the getInternal() will lose this granularity.

return getUrnAspectMap(urns, aspectClasses, isInternalModelsEnabled).entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey,
e -> isInternalModelsEnabled ? toInternalValue(newInternalSnapshot(e.getKey(), e.getValue()))
: toValue(newSnapshot(e.getKey(), e.getValue()))));
}

/**
* Similar to {@link #getInternal(Collection, Set, boolean)} but filter out {@link URN}s which are not in the DB.
*/
Expand All @@ -1089,6 +1107,21 @@ protected Map<URN, VALUE> getInternalNonEmpty(@Nonnull Collection<URN> urns,
: toValue(newSnapshot(e.getKey(), e.getValue()))));
}

/**
* Same as the above but doesn't require the callee to provide the 'isInternalModelsEnabled' flag.
*/
@Nonnull
protected Map<URN, VALUE> getInternalNonEmpty(@Nonnull Collection<URN> urns,
@Nonnull Set<Class<? extends RecordTemplate>> aspectClasses) {
final boolean isInternalModelsEnabled = getResourceLix().testGetAll(_urnClass.getSimpleName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, unless only getAll is calling this method. But there's no restriction for future cases

return getUrnAspectMap(urns, aspectClasses, isInternalModelsEnabled).entrySet()
.stream()
.filter(e -> !e.getValue().isEmpty())
.collect(Collectors.toMap(Map.Entry::getKey,
e -> isInternalModelsEnabled ? toInternalValue(newInternalSnapshot(e.getKey(), e.getValue()))
: toValue(newSnapshot(e.getKey(), e.getValue()))));
}

@Nonnull
private Map<URN, List<UnionTemplate>> getUrnAspectMap(@Nonnull Collection<URN> urns,
@Nonnull Set<Class<? extends RecordTemplate>> aspectClasses, boolean isInternalModelsEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@ public CollectionResult<VALUE, SearchResultMetadata> getSearchQueryCollectionRes
);
}

/**
* Same as the above but doesn't require the callee to provide the 'isInternalModelsEnabled' flag.
* @param searchResult Search result returned from search infra, such as Elasticsearch.
* @param aspectNames List of aspect names that need to be returned.
* @return CollectionResult which contains: 1. aspect values fetched from MySQL DB, 2. Total count 3. Search result metadata.
*/
@Nonnull
public CollectionResult<VALUE, SearchResultMetadata> getSearchQueryCollectionResult(@Nonnull SearchResult<DOCUMENT> searchResult,
@Nullable String[] aspectNames) {
return getSearchQueryCollectionResult(searchResult, aspectNames, getResourceLix().testSearch(_urnClass.getSimpleName()));
}

private URN toEntitySpecificUrn(Urn urn) {
try {
return (URN) (_urnClass.getMethod("createFromUrn", Urn.class).invoke(null, urn));
Expand Down
Loading