added back proper batching of content EntityLists with optimization for
authormh <mh>
Wed, 20 Feb 2002 13:36:33 +0000 (13:36 +0000)
committermh <mh>
Wed, 20 Feb 2002 13:36:33 +0000 (13:36 +0000)
when an id is passed so not to do count(*) in that case.

source/mircoders/producer/ProducerContent.java

index 633de45..84111ef 100755 (executable)
@@ -17,7 +17,7 @@ import mircoders.storage.*;
 
 public class ProducerContent extends Producer {
 
-  private String      contentTemplate = MirConfig.getProp("Producer.Content.Template");
+  private String contentTemplate=MirConfig.getProp("Producer.Content.Template");
 
   public static void main(String argv[]){
     /**
@@ -31,6 +31,8 @@ public class ProducerContent extends Producer {
      * from cron-script. In that case the config has to be initliased.
      * Don't know if is ok that way //rk
      *
+     * ok, i figured that out a few months ago.. -mh
+     *
      */
     //Configuration.initConfig("config");
     System.out.println(MirConfig.getProp("Producer.DocRoot"));
@@ -53,7 +55,8 @@ public class ProducerContent extends Producer {
   }
 
   public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
-                     boolean sync, String id) throws StorageObjectException, ModuleException
+                     boolean sync, String id) throws StorageObjectException,
+                     ModuleException
   {
 
     long                startTime = System.currentTimeMillis();
@@ -66,6 +69,8 @@ public class ProducerContent extends Producer {
     EntityList          batchEntityList;
     EntityUsers         userEntity=null;
 
+    int                 contentBatchsize = 
+            Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
     // production of the content-pages
 
     /** @todo this should be moved to ModuleContent */
@@ -75,20 +80,24 @@ public class ProducerContent extends Producer {
       // if true: produces a single content item
       if(id !=null){
         whereClause += " AND id="+id;
+        // I think this avoids a select count(*)...
+        contentBatchsize=-1;
       }
       batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
-                                                -1, userEntity);
+                                                contentBatchsize, userEntity);
     } else {
       whereClause="is_produced='0' AND is_published='1'";
       //if true produces a single contentitem
       if(id !=null){
         whereClause += " AND id="+id;
+        // I think this avoids a select count(*)...
+        contentBatchsize=-1;
       }
       batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
-                                                -1, userEntity);
+                                                contentBatchsize, userEntity);
     }
 
-    if (batchEntityList!=null) {
+    while (batchEntityList!=null) {
       for(int i=0;i<batchEntityList.size();i++) {
         currentContent = (EntityContent)batchEntityList.elementAt(i);
 
@@ -109,13 +118,22 @@ public class ProducerContent extends Producer {
         }
         catch(Exception e)
         {
-          String errorText = "Producer.Content ERROR while producing content ID:"
+          String errorText = "Producer.Content <font color=red>ERROR</font> while producing content ID:"
                     + currentContent.getId()+", skipping it :: "+e.toString();
           logHTML(htmlout, errorText);
           theLog.printError(errorText);
         }
         pageCount++;
       }//for
+      // if next batch get it...
+      if (batchEntityList.hasNextBatch()){
+        batchEntityList = contentModule.getByWhereClause(whereClause, 
+                                    null, batchEntityList.getNextBatch(),
+                                    contentBatchsize);
+      } else {
+        batchEntityList=null;
+      }
+
     }