From e6f69077b07f1a10e77c3b12208c8e8a87aacf8a Mon Sep 17 00:00:00 2001
From: Daniel <d.hornung@indiscale.com>
Date: Tue, 21 Mar 2023 16:55:43 +0100
Subject: [PATCH] ENH: Initialize auto-inserted files with NULL names.

---
 CHANGELOG.md                                               | 7 +++++--
 .../java/org/caosdb/server/jobs/core/InsertFilesInDir.java | 4 ++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b91d1dca..c8b974ae 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed ###
 
-* The default behavior of the query FIND SomeName [...] (as well as COUNT and SELECT) is being made configurable and changes
+* The default behavior of the query `FIND SomeName [...]` (as well as COUNT and SELECT) is being
+  made configurable and changes:
   * `FIND SomeName` will be interpreted as `FIND <FIND_QUERY_DEFAULT_ROLE>
     SomeName` from now on where `FIND_QUERY_DEFAULT_ROLE` is a newly introduced
     server property.
@@ -21,7 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
     `FIND <FIND_QUERY_DEFAULT_ROLE>`.
   * Of course, administrators can choose to retain the old behavior by setting
     `FIND_QUERY_DEFAULT_ROLE=ENTITY`.
-* CQL now treats `WITH` and `WITH A` equivalently. This is for [#192](https://gitlab.com/caosdb/caosdb-server/-/issues/192).
+* CQL now treats `WITH` and `WITH A` equivalently. Issue: [#192](https://gitlab.com/caosdb/caosdb-server/-/issues/192)
+* The InsertFilesInDir FlagJob now creates File entities without a name.  The previous behavior
+  caused severe performance problems for very large numbers of files. Issue: [#197](https://gitlab.com/caosdb/caosdb-server/-/issues/197)
 
 ### Deprecated ###
 
diff --git a/src/main/java/org/caosdb/server/jobs/core/InsertFilesInDir.java b/src/main/java/org/caosdb/server/jobs/core/InsertFilesInDir.java
index 51c68cdc..d8bba145 100644
--- a/src/main/java/org/caosdb/server/jobs/core/InsertFilesInDir.java
+++ b/src/main/java/org/caosdb/server/jobs/core/InsertFilesInDir.java
@@ -276,9 +276,9 @@ public class InsertFilesInDir extends FlagJob {
    */
   private EntityInterface createInsertFileEntity(String name) {
     if (getTransaction() instanceof WriteTransactionInterface) {
-      return new InsertEntity(name, Role.File);
+        return new InsertEntity((String) null, Role.File);
     }
-    EntityInterface result = new RetrieveEntity(name);
+    EntityInterface result = new RetrieveEntity((String) null);
     result.setRole(Role.File);
     return result;
   }
-- 
GitLab