From 097f3aa987cefdd11dc3e03d04717fba4591086e Mon Sep 17 00:00:00 2001 From: To-om Date: Sun, 28 Jun 2020 09:13:49 +0200 Subject: [PATCH] #1404 Rebuild indexes to ensure their proper use --- .../main/scala/org/thp/thehive/migration/th4/Output.scala | 5 +---- thehive/app/org/thp/thehive/models/Case.scala | 2 +- thehive/app/org/thp/thehive/models/Observable.scala | 2 +- thehive/app/org/thp/thehive/models/Tag.scala | 2 +- thehive/app/org/thp/thehive/services/DatabaseWrapper.scala | 1 + 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala b/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala index fdd4408d2c..894e71e445 100644 --- a/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala +++ b/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala @@ -240,10 +240,7 @@ class Output @Inject() ( .flatMap(_ => cortexSchema.update(db)(LocalUserSrv.getSystemAuthContext)) .map { _ => retrieveExistingData() - db match { - case jdb: JanusDatabase => jdb.removeAllIndexes() - case _ => - } + db.removeAllIndexes() } } } diff --git a/thehive/app/org/thp/thehive/models/Case.scala b/thehive/app/org/thp/thehive/models/Case.scala index 345e53b4e3..39b07e16ea 100644 --- a/thehive/app/org/thp/thehive/models/Case.scala +++ b/thehive/app/org/thp/thehive/models/Case.scala @@ -76,7 +76,7 @@ case class CaseUser() case class CaseCaseTemplate() @VertexEntity -@DefineIndex(IndexType.tryUnique, "number") +@DefineIndex(IndexType.unique, "number") //@DefineIndex(IndexType.fulltext, "title") //@DefineIndex(IndexType.fulltext, "description") //@DefineIndex(IndexType.standard, "startDate") diff --git a/thehive/app/org/thp/thehive/models/Observable.scala b/thehive/app/org/thp/thehive/models/Observable.scala index 237ffd18dd..e35a474903 100644 --- a/thehive/app/org/thp/thehive/models/Observable.scala +++ b/thehive/app/org/thp/thehive/models/Observable.scala @@ -41,6 +41,6 @@ case class RichObservable( def sighted: Boolean = observable.sighted } -@DefineIndex(IndexType.tryUnique, "data") +@DefineIndex(IndexType.unique, "data") @VertexEntity case class Data(data: String) diff --git a/thehive/app/org/thp/thehive/models/Tag.scala b/thehive/app/org/thp/thehive/models/Tag.scala index 2a82a09f86..045962c366 100644 --- a/thehive/app/org/thp/thehive/models/Tag.scala +++ b/thehive/app/org/thp/thehive/models/Tag.scala @@ -7,7 +7,7 @@ import play.api.Logger import scala.util.Try import scala.util.matching.Regex -@DefineIndex(IndexType.tryUnique, "namespace", "predicate", "value") +@DefineIndex(IndexType.unique, "namespace", "predicate", "value") @VertexEntity case class Tag( namespace: String, diff --git a/thehive/app/org/thp/thehive/services/DatabaseWrapper.scala b/thehive/app/org/thp/thehive/services/DatabaseWrapper.scala index c48508c5cb..312569a4a7 100644 --- a/thehive/app/org/thp/thehive/services/DatabaseWrapper.scala +++ b/thehive/app/org/thp/thehive/services/DatabaseWrapper.scala @@ -67,6 +67,7 @@ class DatabaseWrapper(dbProvider: Provider[Database]) extends Database { override def addSchemaIndexes(model: Model, models: Model*): Try[Unit] = db.addSchemaIndexes(model, models: _*) override def addSchemaIndexes(models: Seq[Model]): Try[Unit] = db.addSchemaIndexes(models) override def enableIndexes(): Try[Unit] = db.enableIndexes() + override def removeAllIndexes(): Unit = db.removeAllIndexes() override def addProperty[T](model: String, propertyName: String, mapping: Mapping[_, _, _]): Try[Unit] = db.addProperty(model, propertyName, mapping) override def removeProperty(model: String, propertyName: String, usedOnlyByThisModel: Boolean): Try[Unit] =