I am using the ServerValue Timestamp in my project and I would like to create relation by using the timestamp as a key.
When the "setValue" is executed the timestamp is calculated twice and I have to observe the ".childAdded" and the ".childChanged" to obtain the correct timestamp value. (ಠ_ಠ) (https://firebase.google.com/docs/reference/ios/firebasedatabase/api/reference/Classes/FIRServerValue)
Used frameworks: Firebase (3.15.0), FirebaseAnalytics (3.7.0), FirebaseAuth (3.1.1), FirebaseCore (3.5.2), FirebaseDatabase (3.1.2), FirebaseInstanceID (1.0.9)
Example snippet code in Swift:
ref = FIRDatabase.database().reference()
ref.child("test").observe(.childAdded, with: { snapshot in
if let value = snapshot.value as? Int {
print("Child added, timestamp value: \(value) ")
}
})
ref.child("test").observe(.childChanged, with: { snapshot in
if let value = snapshot.value as? Int {
print("Child change, timestamp value: \(value) ")
}
})
ref.child("test").setValue(["one" : FIRServerValue.timestamp()]) { error, ref in
print("New child inserted.")
}
Console output:
- Child added, timestamp value: 1490950004556
- Child change, timestamp value: 1490950005970
- New child inserted.
If the setValue is executed by an other user (other connected client) then only the "childAdded" event is invoking which is nice :)
Referring to this comment https://stackoverflow.com/a/30244373/4427983 it seems that the timestamp is calculated locally first by the firebase framework. Can I disable somehow this feature and force the framework to calculate the timestamp value only at sever side?