joerghoh commented on code in PR #152:
URL:
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/152#discussion_r1970017985
##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java:
##########
@@ -630,23 +630,23 @@ private boolean addEntry(final Map<String,
List<MapEntry>> entryMap, final Strin
return false;
} else {
List<MapEntry> entries = entryMap.get(key);
- if (entries == null) {
- entries = new ArrayList<>();
- entries.add(entry);
- entryMap.put(key, entries);
- } else {
- List<MapEntry> entriesCopy = new ArrayList<>(entries);
- entriesCopy.add(entry);
- // and finally sort list
- Collections.sort(entriesCopy);
- entryMap.put(key, entriesCopy);
- int size = entriesCopy.size();
- if (size == 10) {
- log.debug(">= 10 MapEntries for {} - check your
configuration", key);
- } else if (size == 100) {
- log.info(">= 100 MapEntries for {} - check your
configuration", key);
- }
+
+ // copy existing list contents (when not empty), add new entry,
then sort
+ List<MapEntry> entriesCopy = new ArrayList<>(entries != null ?
entries : List.of());
+ entriesCopy.add(entry);
+ Collections.sort(entriesCopy);
+
+ // update map with new list
+ entryMap.put(key, entriesCopy);
+
+ // warn when list of entries for one key grows
+ int size = entriesCopy.size();
+ if (size == 10) {
+ log.debug(">= 10 MapEntries for {} - check your
configuration", key);
Review Comment:
It's actually 10 entries, not ">=" :-)
##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java:
##########
@@ -222,30 +223,43 @@ private String getMapEntryRedirect(final MapEntry
mapEntry) {
}
boolean doRemoveVanity(final String path) {
- final String actualContentPath = getActualContentPath(path);
- final List <String> l = vanityTargets.remove(actualContentPath);
- if (l != null){
- for (final String s : l){
- final List<MapEntry> entries = this.resolveMapsMap.get(s);
- if (entries!= null) {
- for (final Iterator<MapEntry> iterator =
entries.iterator(); iterator.hasNext(); ) {
- final MapEntry entry = iterator.next();
- final String redirect = getMapEntryRedirect(entry);
- if (redirect != null &&
redirect.equals(actualContentPath)) {
- iterator.remove();
- }
- }
+ String actualContentPath = getActualContentPath(path);
+ List<String> targets = this.vanityTargets.remove(actualContentPath);
+
+ if (targets != null) {
+ for (String target : targets) {
+ int count = removeEntriesFromResolvesMap(target,
actualContentPath);
+ if (vanityCounter.longValue() >= count) {
+ vanityCounter.addAndGet(-count);
Review Comment:
why was this changed from ``-2`` to ``-count``? While it sounds logically,
is it a bug in the existing implementation?
--
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]