Skip to content

Commit

Permalink
cache EntityType excludeFromIndexes annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
nevillelyh committed Jul 6, 2020
1 parent c46aad4 commit b6b5c61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion datastore/src/main/scala/magnolify/datastore/EntityType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ object EntityField {
type Typeclass[T] = EntityField[T]

def combine[T](caseClass: CaseClass[Typeclass, T]): Record[T] = new Record[T] {
private val excludeFromIndexes: Array[Boolean] = {
val a = new Array[Boolean](caseClass.parameters.length)
caseClass.parameters.foreach { p =>
a(p.index) = getExcludeFromIndexes(p.annotations, s"${caseClass.typeName.full}#${p.label}")
}
a
}

override def fromEntity(v: Entity)(cm: CaseMapper): T =
caseClass.construct { p =>
val f = v.getPropertiesOrDefault(cm.map(p.label), null)
Expand All @@ -81,7 +89,7 @@ object EntityField {
if (vb != null) {
eb.putProperties(
cm.map(p.label),
vb.setExcludeFromIndexes(getExcludeFromIndexes(p.annotations, cm.map(p.label)))
vb.setExcludeFromIndexes(excludeFromIndexes(p.index))
.build()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ object EntityTypeSpec extends MagnolifySpec("EntityType") {
expectException[IllegalArgumentException](
EntityType[DoubleEntityIndex].apply(DoubleEntityIndex(0))
).getMessage ==
"requirement failed: More than one excludeFromIndexes annotation: i"
"requirement failed: More than one excludeFromIndexes annotation: magnolify.datastore.test.DoubleEntityIndex#i"
)

{
Expand Down

0 comments on commit b6b5c61

Please sign in to comment.