snapshot method
Returns a future of the latest snapshot of this document. This is purely for use with queries, and should not be used for anything else.
Note that this feature is not optimized for performance, but for a lower amount of reads to reduce Firestore costs.
Implementation
Future<DocumentSnapshot> snapshot() async {
var latestSnapshot = _latestSnapshot;
if (latestSnapshot != null && latestSnapshot.exists && latestSnapshot.id == id) {
// This object is injected, we need to deserialize it again to compare it
if (latestSnapshot is DocumentSnapshot<Map<String, dynamic>>) {
var capableEngine = DogFirestoreEngine.instance.engine;
var decoded = DogFirestoreEngine.instance.mode
.forType(T, capableEngine)
.deserialize(latestSnapshot, capableEngine);
if (decoded == this) {
return latestSnapshot; // Compare if the object is the same
}
// This object is not injected, we can compare it directly
} else if (latestSnapshot.data() == this) {
return latestSnapshot;
}
}
//if (kDebugMode) print("Snapshot cache miss for $id");
// No similar snapshot exists - This is either a new object, or the object has been modified
var currentSnapshot = selfDocument.get();
_latestSnapshot = await currentSnapshot;
return currentSnapshot;
}