mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-20 21:35:10 +00:00
Minor:refactor fetching assetsCount for individual fields (#23762)
This commit is contained in:
parent
47e953f9d3
commit
83c63e92b1
@ -93,7 +93,7 @@ public class DomainRepository extends EntityRepository<Domain> {
|
|||||||
@Override
|
@Override
|
||||||
public void setFields(Domain entity, Fields fields) {
|
public void setFields(Domain entity, Fields fields) {
|
||||||
entity.withAssets(fields.contains(FIELD_ASSETS) ? getAssets(entity) : null);
|
entity.withAssets(fields.contains(FIELD_ASSETS) ? getAssets(entity) : null);
|
||||||
entity.withAssetsCount(fields.contains(FIELD_ASSETS_COUNT) ? getAssets(entity).size() : 0);
|
entity.withAssetsCount(fields.contains(FIELD_ASSETS_COUNT) ? getAssetsCount(entity) : null);
|
||||||
entity.withParent(getParent(entity));
|
entity.withParent(getParent(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,6 +192,23 @@ public class DomainRepository extends EntityRepository<Domain> {
|
|||||||
return result.entities();
|
return result.entities();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getAssetsCount(Domain entity) {
|
||||||
|
if (inheritedFieldEntitySearch == null) {
|
||||||
|
LOG.warn("Search is unavailable for domain assets count. Returning 0 for consistency.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
InheritedFieldQuery query = InheritedFieldQuery.forDomain(entity.getFullyQualifiedName());
|
||||||
|
return inheritedFieldEntitySearch.getCountForField(
|
||||||
|
query,
|
||||||
|
() -> {
|
||||||
|
LOG.warn(
|
||||||
|
"Search fallback triggered for domain {} count. Returning 0 for consistency.",
|
||||||
|
entity.getFullyQualifiedName());
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public BulkOperationResult bulkAddAssets(String domainName, BulkAssets request) {
|
public BulkOperationResult bulkAddAssets(String domainName, BulkAssets request) {
|
||||||
Domain domain = getByName(null, domainName, getFields("id"));
|
Domain domain = getByName(null, domainName, getFields("id"));
|
||||||
return bulkAssetsOperation(domain.getId(), DOMAIN, Relationship.HAS, request, true);
|
return bulkAssetsOperation(domain.getId(), DOMAIN, Relationship.HAS, request, true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user