Skip to content

Commit f0f0aeb

Browse files
Don't persist documents that we already have (#3650)
1 parent cbdf31d commit f0f0aeb

File tree

6 files changed

+70
-333
lines changed

6 files changed

+70
-333
lines changed

Firestore/Example/Tests/Local/FSTLocalStoreTests.mm

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,9 +1050,9 @@ - (void)testHoldsBackOnlyNonIdempotentTransforms {
10501050
// The sum transform is not idempotent and the backend's updated value is ignored. The
10511051
// ArrayUnion transform is recomputed and includes the backend value.
10521052
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
1053-
Doc("foo/bar", 1, Map("sum", 1337, "array_union", Array("bar"))), {2},
1053+
Doc("foo/bar", 2, Map("sum", 1337, "array_union", Array("bar"))), {2},
10541054
{})];
1055-
FSTAssertChanged(Doc("foo/bar", 1, Map("sum", 1, "array_union", Array("bar", "foo")),
1055+
FSTAssertChanged(Doc("foo/bar", 2, Map("sum", 1, "array_union", Array("bar", "foo")),
10561056
DocumentState::kLocalMutations));
10571057
}
10581058

@@ -1120,6 +1120,26 @@ - (void)testGetHighestUnacknowledgeBatchId {
11201120
XCTAssertEqual(-1, [self.localStore getHighestUnacknowledgedBatchId]);
11211121
}
11221122

1123+
- (void)testOnlyPersistsUpdatesForDocumentsWhenVersionChanges {
1124+
if ([self isTestBaseClass]) return;
1125+
1126+
core::Query query = Query("foo");
1127+
[self allocateQuery:query];
1128+
FSTAssertTargetID(2);
1129+
1130+
[self applyRemoteEvent:FSTTestAddedRemoteEvent(Doc("foo/bar", 1, Map("val", "old")), {2})];
1131+
FSTAssertContains(Doc("foo/bar", 1, Map("val", "old")));
1132+
FSTAssertChanged(Doc("foo/bar", 1, Map("val", "old")));
1133+
1134+
[self applyRemoteEvent:FSTTestAddedRemoteEvent({Doc("foo/bar", 1, Map("val", "new")),
1135+
Doc("foo/baz", 2, Map("val", "new"))},
1136+
{2})];
1137+
// The update to foo/bar is ignored.
1138+
FSTAssertContains(Doc("foo/bar", 1, Map("val", "old")));
1139+
FSTAssertContains(Doc("foo/baz", 2, Map("val", "new")));
1140+
FSTAssertChanged(Doc("foo/baz", 2, Map("val", "new")));
1141+
}
1142+
11231143
@end
11241144

11251145
NS_ASSUME_NONNULL_END

Firestore/Example/Tests/SpecTests/json/limbo_spec_test.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@
611611
"docs": [
612612
{
613613
"key": "collection/a",
614-
"version": 1000,
614+
"version": 1002,
615615
"value": {
616616
"key": "b"
617617
},
@@ -948,7 +948,7 @@
948948
"docs": [
949949
{
950950
"key": "collection/a",
951-
"version": 1000,
951+
"version": 1002,
952952
"value": {
953953
"key": "b"
954954
},
@@ -1055,7 +1055,7 @@
10551055
"added": [
10561056
{
10571057
"key": "collection/a",
1058-
"version": 1000,
1058+
"version": 1002,
10591059
"value": {
10601060
"key": "b"
10611061
},

Firestore/Example/Tests/SpecTests/json/listen_spec_test.json

Lines changed: 0 additions & 287 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,293 +3070,6 @@
30703070
}
30713071
]
30723072
},
3073-
"Deleted documents in cache are fixed": {
3074-
"describeName": "Listens:",
3075-
"itName": "Deleted documents in cache are fixed",
3076-
"tags": [],
3077-
"config": {
3078-
"useGarbageCollection": false,
3079-
"numClients": 1
3080-
},
3081-
"steps": [
3082-
{
3083-
"userListen": [
3084-
2,
3085-
{
3086-
"path": "collection",
3087-
"filters": [
3088-
[
3089-
"key",
3090-
"==",
3091-
"a"
3092-
]
3093-
],
3094-
"orderBys": []
3095-
}
3096-
],
3097-
"stateExpect": {
3098-
"activeTargets": {
3099-
"2": {
3100-
"query": {
3101-
"path": "collection",
3102-
"filters": [
3103-
[
3104-
"key",
3105-
"==",
3106-
"a"
3107-
]
3108-
],
3109-
"orderBys": []
3110-
},
3111-
"resumeToken": ""
3112-
}
3113-
}
3114-
}
3115-
},
3116-
{
3117-
"watchAck": [
3118-
2
3119-
]
3120-
},
3121-
{
3122-
"watchEntity": {
3123-
"docs": [
3124-
{
3125-
"key": "collection/a",
3126-
"version": 1000,
3127-
"value": {
3128-
"key": "a"
3129-
},
3130-
"options": {
3131-
"hasLocalMutations": false,
3132-
"hasCommittedMutations": false
3133-
}
3134-
}
3135-
],
3136-
"targets": [
3137-
2
3138-
]
3139-
}
3140-
},
3141-
{
3142-
"watchCurrent": [
3143-
[
3144-
2
3145-
],
3146-
"resume-token-1000"
3147-
]
3148-
},
3149-
{
3150-
"watchSnapshot": {
3151-
"version": 1000,
3152-
"targetIds": []
3153-
},
3154-
"expect": [
3155-
{
3156-
"query": {
3157-
"path": "collection",
3158-
"filters": [
3159-
[
3160-
"key",
3161-
"==",
3162-
"a"
3163-
]
3164-
],
3165-
"orderBys": []
3166-
},
3167-
"added": [
3168-
{
3169-
"key": "collection/a",
3170-
"version": 1000,
3171-
"value": {
3172-
"key": "a"
3173-
},
3174-
"options": {
3175-
"hasLocalMutations": false,
3176-
"hasCommittedMutations": false
3177-
}
3178-
}
3179-
],
3180-
"errorCode": 0,
3181-
"fromCache": false,
3182-
"hasPendingWrites": false
3183-
}
3184-
]
3185-
},
3186-
{
3187-
"watchEntity": {
3188-
"docs": [
3189-
{
3190-
"key": "collection/a",
3191-
"version": 2000,
3192-
"value": null
3193-
}
3194-
],
3195-
"removedTargets": [
3196-
2
3197-
]
3198-
}
3199-
},
3200-
{
3201-
"watchSnapshot": {
3202-
"version": 2000,
3203-
"targetIds": [
3204-
2
3205-
],
3206-
"resumeToken": "resume-token-2000"
3207-
}
3208-
},
3209-
{
3210-
"watchSnapshot": {
3211-
"version": 2000,
3212-
"targetIds": []
3213-
},
3214-
"expect": [
3215-
{
3216-
"query": {
3217-
"path": "collection",
3218-
"filters": [
3219-
[
3220-
"key",
3221-
"==",
3222-
"a"
3223-
]
3224-
],
3225-
"orderBys": []
3226-
},
3227-
"removed": [
3228-
{
3229-
"key": "collection/a",
3230-
"version": 1000,
3231-
"value": {
3232-
"key": "a"
3233-
},
3234-
"options": {
3235-
"hasLocalMutations": false,
3236-
"hasCommittedMutations": false
3237-
}
3238-
}
3239-
],
3240-
"errorCode": 0,
3241-
"fromCache": false,
3242-
"hasPendingWrites": false
3243-
}
3244-
]
3245-
},
3246-
{
3247-
"userUnlisten": [
3248-
2,
3249-
{
3250-
"path": "collection",
3251-
"filters": [
3252-
[
3253-
"key",
3254-
"==",
3255-
"a"
3256-
]
3257-
],
3258-
"orderBys": []
3259-
}
3260-
],
3261-
"stateExpect": {
3262-
"activeTargets": {}
3263-
}
3264-
},
3265-
{
3266-
"watchRemove": {
3267-
"targetIds": [
3268-
2
3269-
]
3270-
}
3271-
},
3272-
{
3273-
"userListen": [
3274-
4,
3275-
{
3276-
"path": "collection",
3277-
"filters": [],
3278-
"orderBys": []
3279-
}
3280-
],
3281-
"stateExpect": {
3282-
"activeTargets": {
3283-
"4": {
3284-
"query": {
3285-
"path": "collection",
3286-
"filters": [],
3287-
"orderBys": []
3288-
},
3289-
"resumeToken": ""
3290-
}
3291-
}
3292-
}
3293-
},
3294-
{
3295-
"watchAck": [
3296-
4
3297-
]
3298-
},
3299-
{
3300-
"watchEntity": {
3301-
"docs": [
3302-
{
3303-
"key": "collection/a",
3304-
"version": 1000,
3305-
"value": {
3306-
"key": "a"
3307-
},
3308-
"options": {
3309-
"hasLocalMutations": false,
3310-
"hasCommittedMutations": false
3311-
}
3312-
}
3313-
],
3314-
"targets": [
3315-
4
3316-
]
3317-
}
3318-
},
3319-
{
3320-
"watchCurrent": [
3321-
[
3322-
4
3323-
],
3324-
"resume-token-3000"
3325-
]
3326-
},
3327-
{
3328-
"watchSnapshot": {
3329-
"version": 3000,
3330-
"targetIds": []
3331-
},
3332-
"expect": [
3333-
{
3334-
"query": {
3335-
"path": "collection",
3336-
"filters": [],
3337-
"orderBys": []
3338-
},
3339-
"added": [
3340-
{
3341-
"key": "collection/a",
3342-
"version": 1000,
3343-
"value": {
3344-
"key": "a"
3345-
},
3346-
"options": {
3347-
"hasLocalMutations": false,
3348-
"hasCommittedMutations": false
3349-
}
3350-
}
3351-
],
3352-
"errorCode": 0,
3353-
"fromCache": false,
3354-
"hasPendingWrites": false
3355-
}
3356-
]
3357-
}
3358-
]
3359-
},
33603073
"Listens are reestablished after network disconnect": {
33613074
"describeName": "Listens:",
33623075
"itName": "Listens are reestablished after network disconnect",

Firestore/Example/Tests/Util/FSTHelpers.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class TestTargetMetadataProvider : public TargetMetadataProvider {
189189
* `GetQueryDataForTarget` target.
190190
*/
191191
static TestTargetMetadataProvider CreateEmptyResultProvider(
192-
const model::DocumentKey &document_key, const std::vector<model::TargetId> &targets);
192+
const model::ResourcePath &path, const std::vector<model::TargetId> &targets);
193193

194194
/** Sets or replaces the local state for the provided query data. */
195195
void SetSyncedKeys(model::DocumentKeySet keys, local::QueryData query_data);
@@ -284,6 +284,11 @@ firebase::firestore::remote::RemoteEvent FSTTestAddedRemoteEvent(
284284
const model::MaybeDocument &doc,
285285
const std::vector<firebase::firestore::model::TargetId> &addedToTargets);
286286

287+
/** Creates a remote event that inserts a list of documents. */
288+
firebase::firestore::remote::RemoteEvent FSTTestAddedRemoteEvent(
289+
const std::vector<model::MaybeDocument> &doc,
290+
const std::vector<firebase::firestore::model::TargetId> &addedToTargets);
291+
287292
/** Creates a remote event with changes to a document. */
288293
firebase::firestore::remote::RemoteEvent FSTTestUpdateRemoteEvent(
289294
const model::MaybeDocument &doc,

0 commit comments

Comments
 (0)