From 51d5219639d942b7d4bf4d8fe4fc77f58658c4b0 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Tue, 5 Mar 2013 12:04:34 -0500
Subject: [PATCH] Don't optimize immediately after deleting records; instead
 optimize at end of batch processing.

---
 harvest/batch-delete.bat                                  | 7 +++++++
 harvest/batch-delete.sh                                   | 8 ++++++++
 .../src/VuFindConsole/Controller/UtilController.php       | 2 --
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/harvest/batch-delete.bat b/harvest/batch-delete.bat
index d7327683354..318807bd223 100644
--- a/harvest/batch-delete.bat
+++ b/harvest/batch-delete.bat
@@ -58,10 +58,17 @@ md %BASEPATH%\processed
 
 rem Process all the files in the target directory:
 cd %VUFIND_HOME%\util
+set FOUNDSOME=0
 for %%a in (%BASEPATH%\*.delete) do (
+  set FOUNDSOME=1
   echo Processing %%a...
   php deletes.php %%a flat %2
   move %%a %BASEPATH%\processed\ > nul
 )
 
+if "%FOUNDSOME%"=="0" goto end
+
+echo Optimizing index...
+php optimize.php
+
 :end
\ No newline at end of file
diff --git a/harvest/batch-delete.sh b/harvest/batch-delete.sh
index d0f14464c4b..a913293f54e 100755
--- a/harvest/batch-delete.sh
+++ b/harvest/batch-delete.sh
@@ -44,13 +44,21 @@ then
 fi
 
 # Process all the files in the target directory:
+FOUNDSOME=0
 cd $VUFIND_HOME/util
 for file in $BASEPATH/*.delete
 do
   if [ -f $file ]
   then
+    FOUNDSOME=1
     echo "Processing $file ..."
     php deletes.php $file flat $2
     mv $file $BASEPATH/processed/`basename $file`
   fi
 done
+
+if [ "$FOUNDSOME" -eq "1" ]
+then
+  echo "Optimizing index..."
+  php optimize.php
+fi
\ No newline at end of file
diff --git a/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php b/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php
index 0a16b88a7da..253a031af6b 100644
--- a/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php
+++ b/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php
@@ -296,8 +296,6 @@ class UtilController extends AbstractBase
         // Delete, Commit and Optimize if necessary:
         if (!empty($ids)) {
             $solr->deleteRecords($ids);
-            $solr->commit();
-            $solr->optimize();
         }
         return $this->getSuccessResponse();
     }
-- 
GitLab