From d5344754fbf25e1f0bd3d1d4deb3a2403471f64d Mon Sep 17 00:00:00 2001 From: Matt Hicks Date: Mon, 13 May 2024 12:07:01 -0500 Subject: [PATCH] Updated Indexer registration to ignore duplicates --- core/src/main/scala/lightdb/index/Indexer.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/lightdb/index/Indexer.scala b/core/src/main/scala/lightdb/index/Indexer.scala index a9756cda..171c499e 100644 --- a/core/src/main/scala/lightdb/index/Indexer.scala +++ b/core/src/main/scala/lightdb/index/Indexer.scala @@ -19,7 +19,11 @@ trait Indexer[D <: Document[D]] { def withSearchContext[Return](f: SearchContext[D] => IO[Return]): IO[Return] protected[lightdb] def register[F](field: IndexedField[F, D]): Unit = synchronized { - _fields = field :: _fields + fields.find(_.fieldName == field.fieldName) match { + case Some(existing) if existing != field => throw new RuntimeException(s"Index already exists: ${field.fieldName}") + case Some(_) => // Don't add again + case None => _fields = field :: _fields + } } private[lightdb] def delete(id: Id[D]): IO[Unit]