jayendrap commented on code in PR #304:
URL: https://github.com/apache/atlas/pull/304#discussion_r1985017178


##########
repository/src/main/java/org/apache/atlas/glossary/GlossaryService.java:
##########
@@ -119,30 +121,62 @@ public static boolean isNameInvalid(String name) {
      */
     @GraphTransaction
     public List<AtlasGlossary> getGlossaries(int limit, int offset, SortOrder 
sortOrder) throws AtlasBaseException {
-        LOG.debug("==> GlossaryService.getGlossaries({}, {}, {})", limit, 
offset, sortOrder);
+        if (DEBUG_ENABLED) {
+            LOG.debug("==> GlossaryService.getGlossaries({}, {}, {})", limit, 
offset, sortOrder);
+        }
+
+        List<String> glossaryGuids = 
AtlasGraphUtilsV2.findEntityGUIDsByType(GlossaryUtils.ATLAS_GLOSSARY_TYPENAME, 
sortOrder);
+
+        if (CollectionUtils.isEmpty(glossaryGuids)) {
+            return Collections.emptyList();
+        }
 
-        List<String>             glossaryGuids    = 
AtlasGraphUtilsV2.findEntityGUIDsByType(GlossaryUtils.ATLAS_GLOSSARY_TYPENAME, 
sortOrder);
-        PaginationHelper<String> paginationHelper = new 
PaginationHelper<>(glossaryGuids, offset, limit);
+        List<AtlasGlossary> ret = new ArrayList<>();
+        int currentOffset = offset;
+        int maxSize = glossaryGuids.size();
 
-        List<AtlasGlossary>                  ret;
-        List<String>                         guidsToLoad = 
paginationHelper.getPaginatedList();
-        AtlasEntity.AtlasEntitiesWithExtInfo glossaryEntities;
+        // If limit is negative, use maxSize; otherwise, take the minimum of 
limit and maxSize
+        int adjustedLimit = (limit < 0) ? maxSize : Integer.min(maxSize, 
limit);
 
-        if (CollectionUtils.isNotEmpty(guidsToLoad)) {
-            glossaryEntities = 
dataAccess.getAtlasEntityStore().getByIds(guidsToLoad, true, false);
-            ret              = new ArrayList<>();
+        // Enable skipping failed entities during processing
+        RequestContext.get().setSkipFailedEntities(true);
 
-            for (AtlasEntity glossaryEntity : glossaryEntities.getEntities()) {
-                AtlasGlossary glossary = glossaryDTO.from(glossaryEntity);
+        while (ret.size() < adjustedLimit && currentOffset < 
glossaryGuids.size()) {
+            // Fetch next batch of GUIDs
+            PaginationHelper<String> paginationHelper = new 
PaginationHelper<>(glossaryGuids, currentOffset, adjustedLimit - ret.size());

Review Comment:
   can we initialize the PaginationHelper only once and have method in that to 
return the list of guids based on offset and adjusted limit?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to