Skip to content

Commit 885b07b

Browse files
authored
Remove support for setting timestampsInSnapshotsEnabled (#6622)
Snapshots will now always include `FIRTimestamp` values. Use `[FIRTimestamp dateValue]` to convert to `NSDate` if required. `timestampsInSnapshotsEnabled` was deprecated in Firebase 5.16.0 (January 22, 2019) and has defaulted to true since then. Projects that have not enabled `timestampsInSnapshotsEnabled` have logged a warning since Firebase 4.12.0 (April 10, 2018).
1 parent 2e12a73 commit 885b07b

File tree

8 files changed

+25
-123
lines changed

8 files changed

+25
-123
lines changed

Firestore/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Unreleased
22

3+
# v7.0.0
4+
- [changed] **Breaking change:** Removed the `areTimestampsInSnapshotsEnabled`
5+
setting. Timestamp fields that read from a `FIRDocumentSnapshot` now always
6+
return `FIRTimestamp` objects. Use `FIRTimestamp.dateValue` to convert to
7+
`NSDate` if required.
8+
39
# v1.19.0
410
- [changed] Internal improvements for future C++ and Unity support. Includes a
511
breaking change for the Firestore C++ Alpha SDK, but does not affect

Firestore/Example/Tests/Integration/API/FIRFieldsTests.mm

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Google
2+
* Copyright 2017 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,10 +19,10 @@
1919

2020
#import <XCTest/XCTest.h>
2121

22-
#import "Firestore/core/src/util/warnings.h"
23-
2422
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
2523

24+
NS_ASSUME_NONNULL_BEGIN
25+
2626
@interface FIRFieldsTests : FSTIntegrationTestCase
2727
@end
2828

@@ -233,7 +233,7 @@ - (FIRDocumentSnapshot *)snapshotWithTimestamps:(FIRTimestamp *)timestamp {
233233
return [self readDocumentForRef:doc];
234234
}
235235

236-
- (void)testTimestampsInSnapshots {
236+
- (void)testTimestampsAreTruncated {
237237
FIRTimestamp *originalTimestamp = [FIRTimestamp timestampWithSeconds:100 nanoseconds:123456789];
238238
FIRDocumentReference *doc = [self documentRef];
239239
[self writeDocumentRef:doc data:testDataWithTimestamps(originalTimestamp)];
@@ -255,52 +255,7 @@ - (void)testTimestampsInSnapshots {
255255
XCTAssertEqualObjects(truncatedTimestamp, timestampFromData);
256256
XCTAssertEqualObjects(timestampFromSnapshot, timestampFromData);
257257
}
258-
@end
259258

260-
@interface FIRTimestampsInSnapshotsLegacyBehaviorTests : FSTIntegrationTestCase
261259
@end
262260

263-
@implementation FIRTimestampsInSnapshotsLegacyBehaviorTests
264-
265-
- (void)setUp {
266-
[super setUp];
267-
// Settings can only be redefined before client is initialized, so this has to happen in setUp.
268-
FIRFirestoreSettings *settings = self.db.settings;
269-
SUPPRESS_DEPRECATED_DECLARATIONS_BEGIN()
270-
settings.timestampsInSnapshotsEnabled = NO;
271-
SUPPRESS_END()
272-
self.db.settings = settings;
273-
}
274-
275-
- (void)testLegacyBehaviorForTimestampFields {
276-
NSDate *originalDate = [NSDate date];
277-
FIRDocumentReference *doc = [self documentRef];
278-
[self writeDocumentRef:doc
279-
data:testDataWithTimestamps([FIRTimestamp timestampWithDate:originalDate])];
280-
FIRDocumentSnapshot *snapshot = [self readDocumentForRef:doc];
281-
NSDictionary<NSString *, id> *data = [snapshot data];
282-
double microsecond = 0.000001;
283-
284-
NSDate *timestampFromSnapshot = snapshot[@"timestamp"];
285-
NSDate *timestampFromData = data[@"timestamp"];
286-
XCTAssertEqualObjects(timestampFromSnapshot, timestampFromData);
287-
XCTAssertEqualWithAccuracy([timestampFromSnapshot timeIntervalSince1970],
288-
[originalDate timeIntervalSince1970], microsecond);
289-
290-
timestampFromSnapshot = snapshot[@"nested.timestamp2"];
291-
timestampFromData = data[@"nested"][@"timestamp2"];
292-
XCTAssertEqualObjects(timestampFromSnapshot, timestampFromData);
293-
XCTAssertEqualWithAccuracy([timestampFromSnapshot timeIntervalSince1970],
294-
[originalDate timeIntervalSince1970], microsecond);
295-
}
296-
297-
- (void)testLegacyBehaviorForServerTimestampFields {
298-
FIRDocumentReference *doc = [self documentRef];
299-
[self writeDocumentRef:doc data:@{@"when" : [FIRFieldValue fieldValueForServerTimestamp]}];
300-
301-
FIRDocumentSnapshot *snapshot = [self readDocumentForRef:doc];
302-
XCTAssertTrue([snapshot[@"when"] isKindOfClass:[NSDate class]]);
303-
XCTAssertTrue([snapshot.data[@"when"] isKindOfClass:[NSDate class]]);
304-
}
305-
306-
@end
261+
NS_ASSUME_NONNULL_END

Firestore/Source/API/FIRDocumentSnapshot.mm

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Google
2+
* Copyright 2017 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -204,10 +204,7 @@ - (nullable id)objectForKeyedSubscript:(id)key {
204204

205205
- (FieldValueOptions)optionsForServerTimestampBehavior:
206206
(FIRServerTimestampBehavior)serverTimestampBehavior {
207-
SUPPRESS_DEPRECATED_DECLARATIONS_BEGIN()
208-
return FieldValueOptions(InternalServerTimestampBehavior(serverTimestampBehavior),
209-
_snapshot.firestore()->settings().timestamps_in_snapshots_enabled());
210-
SUPPRESS_END()
207+
return FieldValueOptions(InternalServerTimestampBehavior(serverTimestampBehavior));
211208
}
212209

213210
- (id)convertedValue:(FieldValue)value options:(const FieldValueOptions &)options {
@@ -242,12 +239,7 @@ - (id)convertedValue:(FieldValue)value options:(const FieldValueOptions &)option
242239
}
243240

244241
- (id)convertedTimestamp:(const FieldValue &)value options:(const FieldValueOptions &)options {
245-
FIRTimestamp *wrapped = MakeFIRTimestamp(value.timestamp_value());
246-
if (options.timestamps_in_snapshots_enabled()) {
247-
return wrapped;
248-
} else {
249-
return [wrapped dateValue];
250-
}
242+
return MakeFIRTimestamp(value.timestamp_value());
251243
}
252244

253245
- (id)convertedServerTimestamp:(const FieldValue &)value

Firestore/Source/API/FIRFirestoreSettings.mm

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Google
2+
* Copyright 2017 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
#include "Firestore/core/src/api/settings.h"
2020
#include "Firestore/core/src/util/exception.h"
2121
#include "Firestore/core/src/util/string_apple.h"
22-
#include "Firestore/core/src/util/warnings.h"
2322
#include "absl/base/attributes.h"
2423
#include "absl/memory/memory.h"
2524

@@ -32,7 +31,7 @@
3231

3332
// Public constant
3433
ABSL_CONST_INIT extern "C" const int64_t kFIRFirestoreCacheSizeUnlimited =
35-
api::Settings::CacheSizeUnlimited;
34+
Settings::CacheSizeUnlimited;
3635

3736
@implementation FIRFirestoreSettings
3837

@@ -42,7 +41,6 @@ - (instancetype)init {
4241
_sslEnabled = Settings::DefaultSslEnabled;
4342
_dispatchQueue = dispatch_get_main_queue();
4443
_persistenceEnabled = Settings::DefaultPersistenceEnabled;
45-
_timestampsInSnapshotsEnabled = Settings::DefaultTimestampsInSnapshotsEnabled;
4644
_cacheSizeBytes = Settings::DefaultCacheSizeBytes;
4745
}
4846
return self;
@@ -56,24 +54,18 @@ - (BOOL)isEqual:(id)other {
5654
}
5755

5856
FIRFirestoreSettings *otherSettings = (FIRFirestoreSettings *)other;
59-
SUPPRESS_DEPRECATED_DECLARATIONS_BEGIN()
6057
return [self.host isEqual:otherSettings.host] &&
6158
self.isSSLEnabled == otherSettings.isSSLEnabled &&
6259
self.dispatchQueue == otherSettings.dispatchQueue &&
6360
self.isPersistenceEnabled == otherSettings.isPersistenceEnabled &&
64-
self.timestampsInSnapshotsEnabled == otherSettings.timestampsInSnapshotsEnabled &&
6561
self.cacheSizeBytes == otherSettings.cacheSizeBytes;
66-
SUPPRESS_END()
6762
}
6863

6964
- (NSUInteger)hash {
7065
NSUInteger result = [self.host hash];
7166
result = 31 * result + (self.isSSLEnabled ? 1231 : 1237);
7267
// Ignore the dispatchQueue to avoid having to deal with sizeof(dispatch_queue_t).
7368
result = 31 * result + (self.isPersistenceEnabled ? 1231 : 1237);
74-
SUPPRESS_DEPRECATED_DECLARATIONS_BEGIN()
75-
result = 31 * result + (self.timestampsInSnapshotsEnabled ? 1231 : 1237);
76-
SUPPRESS_END()
7769
result = 31 * result + (NSUInteger)self.cacheSizeBytes;
7870
return result;
7971
}
@@ -84,9 +76,6 @@ - (id)copyWithZone:(__unused NSZone *_Nullable)zone {
8476
copy.sslEnabled = _sslEnabled;
8577
copy.dispatchQueue = _dispatchQueue;
8678
copy.persistenceEnabled = _persistenceEnabled;
87-
SUPPRESS_DEPRECATED_DECLARATIONS_BEGIN()
88-
copy.timestampsInSnapshotsEnabled = _timestampsInSnapshotsEnabled;
89-
SUPPRESS_END()
9079
copy.cacheSizeBytes = _cacheSizeBytes;
9180
return copy;
9281
}
@@ -119,12 +108,11 @@ - (void)setCacheSizeBytes:(int64_t)cacheSizeBytes {
119108
_cacheSizeBytes = cacheSizeBytes;
120109
}
121110

122-
- (api::Settings)internalSettings {
123-
api::Settings settings;
111+
- (Settings)internalSettings {
112+
Settings settings;
124113
settings.set_host(util::MakeString(_host));
125114
settings.set_ssl_enabled(_sslEnabled);
126115
settings.set_persistence_enabled(_persistenceEnabled);
127-
settings.set_timestamps_in_snapshots_enabled(_timestampsInSnapshotsEnabled);
128116
settings.set_cache_size_bytes(_cacheSizeBytes);
129117
return settings;
130118
}

Firestore/Source/Public/FirebaseFirestore/FIRFirestoreSettings.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Google
2+
* Copyright 2017 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,26 +48,6 @@ NS_SWIFT_NAME(FirestoreSettings)
4848
/** Set to false to disable local persistent storage. */
4949
@property(nonatomic, getter=isPersistenceEnabled) BOOL persistenceEnabled;
5050

51-
/**
52-
* Specifies whether to use FIRTimestamps for timestamp fields in FIRDocumentSnapshots. This is
53-
* now enabled by default and should not be disabled.
54-
*
55-
* Previously, Firestore returned timestamp fields as NSDate but NSDate is implemented as a double
56-
* which loses precision and causes unexpected behavior when using a timestamp from a snapshot as a
57-
* part of a subsequent query.
58-
*
59-
* So now Firestore returns FIRTimestamp values instead of NSDate, avoiding this kind of problem.
60-
*
61-
* To opt into the old behavior of returning NSDate objects, you can temporarily set
62-
* areTimestampsInSnapshotsEnabled to false.
63-
*
64-
* @deprecated This setting now defaults to true and will be removed in a future release. If you are
65-
* already setting it to true, just remove the setting. If you are setting it to false, you should
66-
* update your code to expect FIRTimestamp objects instead of NSDate and then remove the setting.
67-
*/
68-
@property(nonatomic, getter=areTimestampsInSnapshotsEnabled) BOOL timestampsInSnapshotsEnabled
69-
__attribute__((deprecated));
70-
7151
/**
7252
* Sets the cache size threshold above which the SDK will attempt to collect least-recently-used
7353
* documents. The size is not a guarantee that the cache will stay below that size, only that if

Firestore/core/src/api/settings.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,18 +27,15 @@ constexpr bool Settings::DefaultSslEnabled;
2727
constexpr bool Settings::DefaultPersistenceEnabled;
2828
constexpr int64_t Settings::DefaultCacheSizeBytes;
2929
constexpr int64_t Settings::MinimumCacheSizeBytes;
30-
constexpr bool Settings::DefaultTimestampsInSnapshotsEnabled;
3130

3231
size_t Settings::Hash() const {
3332
return util::Hash(host_, ssl_enabled_, persistence_enabled_,
34-
timestamps_in_snapshots_enabled_, cache_size_bytes_);
33+
cache_size_bytes_);
3534
}
3635

3736
bool operator==(const Settings& lhs, const Settings& rhs) {
3837
return lhs.host_ == rhs.host_ && lhs.ssl_enabled_ == rhs.ssl_enabled_ &&
3938
lhs.persistence_enabled_ == rhs.persistence_enabled_ &&
40-
lhs.timestamps_in_snapshots_enabled_ ==
41-
rhs.timestamps_in_snapshots_enabled_ &&
4239
lhs.cache_size_bytes_ == rhs.cache_size_bytes_;
4340
}
4441

Firestore/core/src/api/settings.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/*
3-
* Copyright 2019 Google
3+
* Copyright 2019 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -40,7 +40,6 @@ class Settings {
4040
static constexpr int64_t DefaultCacheSizeBytes = 100 * 1024 * 1024;
4141
static constexpr int64_t MinimumCacheSizeBytes = 1 * 1024 * 1024;
4242
static constexpr int64_t CacheSizeUnlimited = -1;
43-
static constexpr bool DefaultTimestampsInSnapshotsEnabled = true;
4443

4544
Settings() = default;
4645

@@ -65,13 +64,6 @@ class Settings {
6564
return persistence_enabled_;
6665
}
6766

68-
void set_timestamps_in_snapshots_enabled(bool value) {
69-
timestamps_in_snapshots_enabled_ = value;
70-
}
71-
bool timestamps_in_snapshots_enabled() const {
72-
return timestamps_in_snapshots_enabled_;
73-
}
74-
7567
void set_cache_size_bytes(int64_t value) {
7668
cache_size_bytes_ = value;
7769
}
@@ -90,7 +82,6 @@ class Settings {
9082
std::string host_ = DefaultHost;
9183
bool ssl_enabled_ = DefaultSslEnabled;
9284
bool persistence_enabled_ = DefaultPersistenceEnabled;
93-
bool timestamps_in_snapshots_enabled_ = DefaultTimestampsInSnapshotsEnabled;
9485
int64_t cache_size_bytes_ = DefaultCacheSizeBytes;
9586
};
9687

Firestore/core/src/model/field_value_options.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Google
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,23 +31,16 @@ class FieldValueOptions {
3131
* Creates an FieldValueOptions instance that specifies deserialization
3232
* behavior for pending server timestamps.
3333
*/
34-
FieldValueOptions(ServerTimestampBehavior server_timestamp_behavior,
35-
bool timestamps_in_snapshots_enabled)
36-
: server_timestamp_behavior_(server_timestamp_behavior),
37-
timestamps_in_snapshots_enabled_(timestamps_in_snapshots_enabled) {
34+
explicit FieldValueOptions(ServerTimestampBehavior server_timestamp_behavior)
35+
: server_timestamp_behavior_(server_timestamp_behavior) {
3836
}
3937

4038
ServerTimestampBehavior server_timestamp_behavior() const {
4139
return server_timestamp_behavior_;
4240
}
4341

44-
bool timestamps_in_snapshots_enabled() const {
45-
return timestamps_in_snapshots_enabled_;
46-
}
47-
4842
private:
4943
ServerTimestampBehavior server_timestamp_behavior_;
50-
bool timestamps_in_snapshots_enabled_;
5144
};
5245

5346
} // namespace model

0 commit comments

Comments
 (0)