From b5d7434c88fc238792d9e8db0ddcb05aa3d8e681 Mon Sep 17 00:00:00 2001
From: anttil <anttil>
Date: Tue, 15 Jan 2013 10:39:09 +0000
Subject: [PATCH] BIS-165 / SP-286: Exporting "for batch update" is very slow

SVN: 28101
---
 .../ui/TypedTableGridColumnDefinitionUI.java     |  6 ++++++
 .../specific/GridCustomColumnDefinition.java     |  6 ++++++
 .../client/web/server/CommonClientService.java   | 16 ++++++++++++++++
 .../server/resultset/CachedResultSetManager.java |  6 ++++++
 .../generic/shared/basic/IColumnDefinition.java  |  3 +++
 .../dto/TypedTableGridColumnDefinition.java      |  6 ++++++
 .../resultset/CachedResultSetManagerTest.java    |  6 ++++++
 7 files changed, 49 insertions(+)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/TypedTableGridColumnDefinitionUI.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/TypedTableGridColumnDefinitionUI.java
index f8fd6027725..d557d2f3445 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/TypedTableGridColumnDefinitionUI.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/TypedTableGridColumnDefinitionUI.java
@@ -121,4 +121,10 @@ public class TypedTableGridColumnDefinitionUI<T extends Serializable> extends
     {
         return header.tryGetVocabulary();
     }
+
+    @Override
+    public boolean isCustom()
+    {
+        return false;
+    }
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GridCustomColumnDefinition.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GridCustomColumnDefinition.java
index 51fbc2fdbee..693e87981fb 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GridCustomColumnDefinition.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GridCustomColumnDefinition.java
@@ -140,4 +140,10 @@ public class GridCustomColumnDefinition<T> implements IColumnDefinitionUI<T>
     private GridCustomColumnDefinition()
     {
     }
+
+    @Override
+    public boolean isCustom()
+    {
+        return true;
+    }
 }
\ No newline at end of file
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java
index 5b70afc2a01..c9fdce86c68 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java
@@ -119,6 +119,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.metaproject.IMetapr
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.metaproject.MetaprojectIdentifierId;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.metaproject.MetaprojectTechIdId;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.id.sample.SampleTechIdId;
+import ch.systemsx.cisd.openbis.generic.shared.basic.IColumnDefinition;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolder;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithPermId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IIdHolder;
@@ -295,6 +296,21 @@ public final class CommonClientService extends AbstractClientService implements
         // Not directly needed but this refreshes the session.
         String session = getSessionToken();
         final TableExportCriteria<T> exportCriteria = getAndRemoveExportCriteria(exportDataKey);
+
+        // Remove custom column definitions, as they are not needed in export (and are expensive to
+        // calculate).
+        Set<IColumnDefinition<T>> availableColumns = exportCriteria.getAvailableColumns();
+        Set<IColumnDefinition<T>> nonCustomColumns = new HashSet<IColumnDefinition<T>>();
+        for (IColumnDefinition<T> def : availableColumns)
+        {
+            if (def.isCustom() == false)
+            {
+                nonCustomColumns.add(def);
+            }
+        }
+        availableColumns.retainAll(nonCustomColumns);
+        exportCriteria.getColumnDefs().retainAll(nonCustomColumns);
+
         final GridRowModels<T> entities = fetchCachedEntities(exportCriteria);
         EntityKind entityKindForUpdate = exportCriteria.getEntityKindForUpdateOrNull();
         if (entityKindForUpdate != null)
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java
index fb9629d311b..991979b056b 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManager.java
@@ -223,6 +223,12 @@ public final class CachedResultSetManager<K> implements IResultSetManager<K>, Se
                         {
                             throw new UnsupportedOperationException();
                         }
+
+                        @Override
+                        public boolean isCustom()
+                        {
+                            return false;
+                        }
                     });
             }
             this.customColumnsProvider = customColumnsProvider;
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/IColumnDefinition.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/IColumnDefinition.java
index b5a1ce152a0..efde92ff914 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/IColumnDefinition.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/IColumnDefinition.java
@@ -48,4 +48,7 @@ public interface IColumnDefinition<T> extends IsSerializable
     /** Tries to get specified property or <code>null</code> if not found. */
     String tryToGetProperty(String key);
 
+    /** Returns true if this is a custom column */
+    boolean isCustom();
+
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/TypedTableGridColumnDefinition.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/TypedTableGridColumnDefinition.java
index bba96e8f7ae..e5fc51a99da 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/TypedTableGridColumnDefinition.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/TypedTableGridColumnDefinition.java
@@ -106,4 +106,10 @@ public class TypedTableGridColumnDefinition<T extends Serializable> implements
         // The check of index is needed because the column is applied to the wrong model
         return index < values.size() ? values.get(index) : null;
     }
+
+    @Override
+    public boolean isCustom()
+    {
+        return false;
+    }
 }
\ No newline at end of file
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManagerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManagerTest.java
index 5260ac348bf..4765ac38765 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManagerTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/resultset/CachedResultSetManagerTest.java
@@ -1154,6 +1154,12 @@ public final class CachedResultSetManagerTest extends AssertJUnit
                     return "a".equals(key) ? "42" : null;
                 }
 
+                @Override
+                public boolean isCustom()
+                {
+                    return false;
+                }
+
             };
     }
 
-- 
GitLab