Skip to content

Commit

Permalink
Optimize call to fetch resources
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 13, 2024
1 parent dc964ac commit cc973c6
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public <T> Set<T> fetchAllDocuments(String pluginIndex, Class<T> clazz) {

LOGGER.debug("Found {} documents in {} for source_idx: {}", resourceIds.size(), resourceSharingIndex, pluginIndex);

return getResourcesFromIds(resourceIds, pluginIndex, clazz);
return resourceIds.isEmpty() ? Set.of() : getResourcesFromIds(resourceIds, pluginIndex, clazz);

} catch (Exception e) {
LOGGER.error("Failed to fetch documents from {} for source_idx: {}", resourceSharingIndex, pluginIndex, e);
Expand Down Expand Up @@ -435,7 +435,7 @@ public <T> Set<T> fetchDocumentsForAGivenScope(

LOGGER.debug("Found {} documents matching the criteria in {}", resourceIds.size(), resourceSharingIndex);

return getResourcesFromIds(resourceIds, pluginIndex, clazz);
return resourceIds.isEmpty() ? Set.of() : getResourcesFromIds(resourceIds, pluginIndex, clazz);

} catch (Exception e) {
LOGGER.error(
Expand Down Expand Up @@ -526,7 +526,7 @@ public <T> Set<T> fetchDocumentsByField(String pluginIndex, String field, String

LOGGER.info("Found {} documents in {} where {} = {}", resourceIds.size(), resourceSharingIndex, field, value);

return getResourcesFromIds(resourceIds, pluginIndex, clazz);
return resourceIds.isEmpty() ? Set.of() : getResourcesFromIds(resourceIds, pluginIndex, clazz);
} catch (Exception e) {
LOGGER.error("Failed to fetch documents from {} where {} = {}", resourceSharingIndex, field, value, e);
throw new RuntimeException("Failed to fetch documents: " + e.getMessage(), e);
Expand Down

0 comments on commit cc973c6

Please sign in to comment.