Author: andreas
Date: Wed Aug 15 13:44:33 2007
New Revision: 566334
URL: http://svn.apache.org/viewvc?view=rev&rev=566334
Log:
Check meta data key only if no values exist (performance)
Modified:
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java?view=diff&rev=566334&r1=566333&r2=566334
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java Wed Aug 15 13:44:33 2007
@@ -18,6 +18,8 @@
package org.apache.lenya.cms.repository;
import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceManager;
@@ -74,19 +76,34 @@
}
public String[] getValues(String key) throws MetaDataException {
- checkKey(key);
- return getHandler().getValues(this.namespaceUri, key);
+ String[] values = getHandler().getValues(this.namespaceUri, key);
+ if (values.length == 0) {
+ checkKey(key);
+ }
+ return values;
}
public String getFirstValue(String key) throws MetaDataException {
- checkKey(key);
String[] values = getValues(key);
if (values.length == 0) {
+ checkKey(key);
return null;
} else {
return values[0];
}
}
+
+ /**
+ * Cache for better performance.
+ */
+ private Set availableKeys;
+
+ protected Set availableKeys() {
+ if (this.availableKeys == null) {
+ this.availableKeys = new HashSet(Arrays.asList(getAvailableKeys()));
+ }
+ return this.availableKeys;
+ }
public String[] getAvailableKeys() {
Element[] elements;
@@ -156,7 +173,7 @@
}
public boolean isValidAttribute(String key) {
- return Arrays.asList(getAvailableKeys()).contains(key);
+ return availableKeys().contains(key);
}
public long getLastModified() throws MetaDataException {
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.