joerghoh commented on code in PR #78:
URL:
https://github.com/apache/sling-org-apache-sling-distribution-core/pull/78#discussion_r4209029104
##########
src/main/java/org/apache/sling/distribution/queue/impl/resource/ResourceQueueUtils.java:
##########
@@ -307,6 +314,29 @@ public static int getResourceCount(Resource root) {
return getEntries(root, 0, -1).size();
}
+ /**
+ * Like getResourceCount(), but bounds the amount of traversal done: once
more than
+ * STATUS_ITEMS_COUNT_CAP entries have been seen, stops early and returns
STATUS_ITEMS_COUNT_CAP
+ * instead of the exact count. Intended for status/console displays on
potentially very large
+ * queues, where an exact count is not required and a full traversal would
be too expensive.
+ * Callers that need the exact size should use getResourceCount() instead.
+ */
+ public static int getResourceCountCapped(Resource root) {
+ Iterator<Resource> it = new ResourceIterator(root, RESOURCE_FOLDER,
false, true);
+
+ int count = 0;
+ while (it.hasNext()) {
+ it.next();
+ count++;
+
+ if (count > STATUS_ITEMS_COUNT_CAP) {
Review Comment:
nitpick: You could add this condition also into the ``while`` loop, to make
the intention clearer.
--
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]