Perform cache refresh after restore in background thread

Caller of the /api/admin/backup API might run into HTTP
timeouts for large projects sets.

Change-Id: Ia9c1e9d64b44ff8658b459f487386230aa0877e4
Signed-off-by: Michael Ochmann <michael.ochmann@sap.com>
diff --git a/org.eclipse.skalli.core/src/main/java/org/eclipse/skalli/core/rest/admin/ProjectBackupResource.java b/org.eclipse.skalli.core/src/main/java/org/eclipse/skalli/core/rest/admin/ProjectBackupResource.java
index c9a9225..e6defa7 100644
--- a/org.eclipse.skalli.core/src/main/java/org/eclipse/skalli/core/rest/admin/ProjectBackupResource.java
+++ b/org.eclipse.skalli.core/src/main/java/org/eclipse/skalli/core/rest/admin/ProjectBackupResource.java
@@ -25,6 +25,7 @@
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.eclipse.skalli.commons.CollectionUtils;
+import org.eclipse.skalli.commons.ThreadPool;
 import org.eclipse.skalli.core.storage.FileStorageComponent;
 import org.eclipse.skalli.services.BundleProperties;
 import org.eclipse.skalli.services.ServiceFilter;
@@ -186,11 +187,19 @@
         }
 
         // ensure that the persistence service attached to the storage
-        // refreshes all caches and reloads all entities
-        PersistenceService persistenceService = Services.getService(PersistenceService.class);
-        if (persistenceService != null) {
-            persistenceService.refreshAll();
-        }
+        // refreshes all caches and reloads all entities --- do that
+        // in the background, otherwise we might run into timeouts
+        ThreadPool.submit(new Runnable() {
+            @Override
+            public void run() {
+                PersistenceService persistenceService = Services.getService(PersistenceService.class);
+                if (persistenceService != null) {
+                    LOG.info("Refreshing all caches");
+                    persistenceService.refreshAll();
+                }
+            }
+        });
+
         setStatus(Status.SUCCESS_NO_CONTENT);
         return null;
     }