Hello!
I'm trying to migrate to Lift 2.5-M1 from 2.4
But my tests didn't pass after updating.
Some debugging helped to find out the reason:
Previousely at
net.liftweb.record.Field the setBox method was:
def setBox(in: Box[MyType]): Box[MyType] = synchronized {
needsDefault = false
data = in match {
case _ if !canWrite_? => Failure(noValueErrorMessage)
case Full(_) => set_!(in)
case _ if optional_? => set_!(in)
case (f: Failure) => set_!(f) // preserve failures set in
case _ => Failure(notOptionalErrorMessage)
}
dirty_?(true)
data
}
Now it became (2.5-M1):
def setBox(in: Box[MyType]): Box[MyType] = synchronized {
needsDefault = false
val oldValue = valueBox
data = in match {
case _ if !canWrite_? => Failure(noValueErrorMessage)
case Full(_) => set_!(in)
case _ if optional_? => set_!(in)
case (f: Failure) => set_!(f) // preserve failures set in
case _ => Failure(notOptionalErrorMessage)
}
val same = (oldValue, valueBox) match {
case (Full(ov), Full(nv)) => ov == nv
case (a, b) => a == b
}
dirty_?(!same)
data
}
Here it is checked if value actually have changed, before setting to dirty. And this seems logical.
But at my code (i'm implementing Neo4jRecord) I'm overriding valueBox this way:
override def valueBox: Box[MyType] = synchronized {
if (owner.node.isEmpty || dirty_?) super.valueBox
else if (canRead_?) getNodeValueBox
else getNodeValueBox.flatMap(obscure)
}
to get the value from the record if corresponding node wasn't created yet, or if the field is dirty (changes was not yet applied to node), other way read the value from corresponding node.
Of course, I can override the setBox method at my Neo4jField, but before doing so,
I would ensure why
val same = (oldValue, valueBox)
really needs a valueBox to compare, couldn't there be just set data ?
As I see using data there instead of valueBox will bring nano-performance optimisation :)
And what is more important will isolate this change.
Should I open ticket, or just override setBox?