[seam-commits] Seam SVN: r10046 - in trunk/examples/wiki/src: main/org/jboss/seam/wiki/core/search and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sat Feb 14 23:59:21 EST 2009


Author: christian.bauer at jboss.com
Date: 2009-02-14 23:59:20 -0500 (Sat, 14 Feb 2009)
New Revision: 10046

Modified:
   trunk/examples/wiki/src/etc/META-INF/persistence-prod-war.xml
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/IndexManager.java
Log:
Wiki manual indexing performance improvements

Modified: trunk/examples/wiki/src/etc/META-INF/persistence-prod-war.xml
===================================================================
--- trunk/examples/wiki/src/etc/META-INF/persistence-prod-war.xml	2009-02-15 03:54:51 UTC (rev 10045)
+++ trunk/examples/wiki/src/etc/META-INF/persistence-prod-war.xml	2009-02-15 04:59:20 UTC (rev 10046)
@@ -22,7 +22,7 @@
             <property name="hibernate.search.default.directory_provider"
                       value="org.hibernate.search.store.FSDirectoryProvider"/>
             <property name="hibernate.search.default.indexBase" value="lacewikiIndex"/>
-            <property name="hibernate.search.worker.batch_size" value="50"/>
+            <property name="hibernate.search.worker.batch_size" value="500"/>
 
             <!-- Run the Hibernate bytecode instrumentation at deployment time, for lazy loading of @ToOne and byte[] properties -->
             <!-- TODO: That doesn't work for me, using the enhancer in build.xml manually -->

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/IndexManager.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/IndexManager.java	2009-02-15 03:54:51 UTC (rev 10045)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/IndexManager.java	2009-02-15 04:59:20 UTC (rev 10046)
@@ -11,6 +11,7 @@
 import org.jboss.seam.annotations.async.Asynchronous;
 import org.jboss.seam.log.Log;
 import org.jboss.seam.wiki.util.Progress;
+import org.jboss.seam.wiki.core.model.WikiNode;
 
 import javax.persistence.EntityManager;
 import javax.transaction.UserTransaction;
@@ -28,7 +29,7 @@
     static Log log;
 
     // TODO: Read the Hibernate Seach configuration option instead, when it becomes available as an API
-    public int batchSize = 50;
+    public int batchSize = 500;
 
     /**
      * Runs asynchronously and re-indexes the given entity class after purging the index.
@@ -38,6 +39,7 @@
      */
     @Asynchronous
     public void rebuildIndex(Class entityClass, Progress progress) {
+
         log.info("asynchronously rebuilding Lucene index for entity: " + entityClass);
 
         UserTransaction userTx = null;
@@ -73,10 +75,17 @@
             em = (EntityManager) Component.getInstance("entityManager");
             ftSession = (FullTextSession)em.getDelegate();
 
-            userTx.begin();
+            // TODO: Let's run this in auto-commit mode, assuming we have READ COMMITTED isolation anyway and non-repeatable reads
+            //userTx.setTransactionTimeout(3600);
+            //userTx.begin();
 
             // Use HQL instead of Criteria to eager fetch lazy properties
-            ScrollableResults cursor = ftSession.createQuery("select o from " + entityClass.getName() + " o fetch all properties").scroll();
+            String query = "select o from " + entityClass.getName() + " o fetch all properties";
+            if (WikiNode.class.isAssignableFrom(entityClass)) {
+                // If it's a WikiNode, fetch the associated User instances, avoiding N+1 selects
+                query = "select o from " + entityClass.getName() + " o inner join fetch o.createdBy left join fetch o.lastModifiedBy fetch all properties";
+            }
+            ScrollableResults cursor = ftSession.createQuery(query).scroll();
 
             cursor.last();
             int count = cursor.getRowNumber() + 1;
@@ -104,17 +113,19 @@
                 }
             }
             cursor.close();
-            userTx.commit();
+            //userTx.commit();
 
             progress.setStatus(Progress.COMPLETE);
             log.debug("indexing complete of entity class: " + entityClass);
 
         } catch (Exception ex) {
+            /*
             try {
                 if (userTx != null) userTx.rollback();
             } catch (Exception rbEx) {
                 rbEx.printStackTrace();
             }
+            */
             throw new RuntimeException(ex);
         }
 




More information about the seam-commits mailing list