joerghoh commented on code in PR #245:
URL:
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/245#discussion_r4723081481
##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java:
##########
@@ -210,6 +216,31 @@ private void execute() {
}
}
+ // Returns an iterator over resources with a sling:alias property,
+ // using paged sorting when enabled and falling back to an unpaged
query.
+ @NotNull
+ private Iterator<Resource> getQueryIterator(@NotNull ResourceResolver
resolver) {
+ String baseQueryString = generateAliasQuery();
+ Iterator<Resource> it;
+ if (PAGING_BEHAVIOUR == QueryBuildHelper.UNPAGED_QUERY) {
+ log.debug("query behaviour is set to unpaged");
+ it = queryUnpaged(baseQueryString, resolver);
+ } else {
+ try {
+ String queryStringWithSort =
+ baseQueryString + " AND FIRST([sling:alias]) >=
'%s' ORDER BY FIRST([sling:alias])";
+ it = new PagedQueryIterator("alias", "sling:alias",
resolver, queryStringWithSort, 2000);
+ } catch (QuerySyntaxException ex) {
+ log.debug("sort with first() not supported, falling back
to base query", ex);
+ it = queryUnpaged(baseQueryString, resolver);
+ } catch (UnsupportedOperationException ex) {
+ log.debug("query failed as unsupported, retrying without
paging/sorting", ex);
Review Comment:
Do we really need that exception? I think that even on DEBUG the root-cause
of that exception is quite clear, so I would not log it.
```suggestion
log.debug("query failed as unsupported, retrying without
paging/sorting");
```
##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/QueryBuildHelper.java:
##########
@@ -45,4 +50,51 @@ public static String escapeString(String input) {
public static String excludeSystemPath() {
return String.format("NOT isdescendantnode('%s')",
escapeString(JCR_SYSTEM_PATH));
}
+
+ public static final int UNPAGED_QUERY = 0;
+ public static final int PAGED_QUERY = 1;
+
+ /**
+ * Resolves the query paging behavior from a system property.
+ *
+ * <p>Reads the system property named by {@code propname} and parses it as
an integer.
+ * If the property is null, blank, unparseable, or not equal to {@link
#UNPAGED_QUERY}
+ * or {@link #PAGED_QUERY}, this method logs an error (when invalid) and
falls back to
+ * {@link #PAGED_QUERY}.
+ *
+ * @param propname the name of the system property to read; may be null or
blank
+ * @return {@link #UNPAGED_QUERY} or {@link #PAGED_QUERY}, defaulting to
{@link #PAGED_QUERY}
+ */
+ // TODO: update when more paging methods are added
+ public static int getPagingBehaviour(String propname) {
Review Comment:
I suggest to use an enum as return value.
##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java:
##########
@@ -481,6 +487,34 @@ private String diagnoseDubiousVanityPath(String resource,
String path) {
return reason.isEmpty() ? "" : String.format("'%s', value '%s': %s",
resource, path, reason);
}
+ // Returns an iterator over resources with a sling:vanityPath property,
+ // using paged sorting when enabled and falling back to an unpaged query.
+ @NotNull
+ private Iterator<Resource> getQueryIterator(@NotNull ResourceResolver
resolver) {
+ String baseQueryString =
+ "SELECT [sling:vanityPath], [sling:redirect],
[sling:redirectStatus]" + " FROM [nt:base]" + " WHERE "
+ + QueryBuildHelper.excludeSystemPath() + " AND
[sling:vanityPath] IS NOT NULL";
+
+ Iterator<Resource> it;
+ if (PAGING_BEHAVIOUR == QueryBuildHelper.UNPAGED_QUERY) {
+ log.debug("query behaviour is set to unpaged");
+ it = queryUnpaged(baseQueryString, resolver);
+ } else {
+ try {
+ String queryStringWithSort =
+ baseQueryString + " AND FIRST([sling:vanityPath]) >=
'%s' ORDER BY FIRST([sling:vanityPath])";
+ it = new PagedQueryIterator("vanity path", PROP_VANITY_PATH,
resolver, queryStringWithSort, 2000);
+ } catch (QuerySyntaxException ex) {
+ log.debug("sort with first() not supported, falling back to
base query", ex);
+ it = queryUnpaged(baseQueryString, resolver);
+ } catch (UnsupportedOperationException ex) {
+ log.debug("query failed as unsupported, retrying without
paging/sorting", ex);
Review Comment:
same as above, the exception does not give any value.
```suggestion
log.debug("query failed as unsupported, retrying without
paging/sorting");
```
##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java:
##########
@@ -64,7 +64,11 @@ class AliasHandler {
private final ReentrantLock initializing;
- private final Logger log = LoggerFactory.getLogger(AliasHandler.class);
+ private static final Logger log =
LoggerFactory.getLogger(AliasHandler.class);
+
+ // constants for paging behaviour as obtained from system property
+ static final String PAGING_BEHAVIOUR_PROPNAME =
"sling.resourceresoolver.aliasinit";
Review Comment:
```suggestion
static final String PAGING_BEHAVIOUR_PROPNAME =
"sling.resourceresolver.aliasinit";
```
##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java:
##########
@@ -81,6 +81,10 @@ public class VanityPathHandler {
private final Logger log =
LoggerFactory.getLogger(VanityPathHandler.class);
+ // constants for paging behaviour as obtained from system property
+ static final String PAGING_BEHAVIOUR_PROPNAME =
"sling.resourceresoolver.vpinit";
Review Comment:
```suggestion
static final String PAGING_BEHAVIOUR_PROPNAME =
"sling.resourceresolver.vpinit";
```
##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java:
##########
@@ -481,6 +487,34 @@ private String diagnoseDubiousVanityPath(String resource,
String path) {
return reason.isEmpty() ? "" : String.format("'%s', value '%s': %s",
resource, path, reason);
}
+ // Returns an iterator over resources with a sling:vanityPath property,
+ // using paged sorting when enabled and falling back to an unpaged query.
+ @NotNull
+ private Iterator<Resource> getQueryIterator(@NotNull ResourceResolver
resolver) {
Review Comment:
A topic for the next round of refactoring:
This method exists almost identical in the AliasHandler as well. Does it
make sense refactor the core logic into a method ``Iterator<Resource>
getQueryIteratorGeneric( ResourceResolver resolver, String baseQuery, String
sortingExtension)``?
--
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]