Skip to content

Commit

Permalink
Updated Indexer registration to ignore duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed May 13, 2024
1 parent ca47aea commit d534475
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/src/main/scala/lightdb/index/Indexer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit d534475

Please sign in to comment.