Skip to content

Fix startAfter/endBefore for orderByKeys queries - #7403

Merged
jmwski merged 13 commits into
masterfrom
jw/orderbykey-start-after
Feb 10, 2021
Merged

Fix startAfter/endBefore for orderByKeys queries#7403
jmwski merged 13 commits into
masterfrom
jw/orderbykey-start-after

Conversation

@jmwski

@jmwski jmwski commented Jan 29, 2021

Copy link
Copy Markdown
Contributor

We should not be passing a fallback key to startAfter if we're querying on a key index. The indexValue is the key in this case.

Comment thread FirebaseDatabase/Tests/Integration/FIRDatabaseQueryTests.m Outdated
Comment thread FirebaseDatabase/Tests/Integration/FIRDatabaseQueryTests.m Outdated
Comment on lines +215 to +217
if ([startAfterValue isKindOfClass:[NSString class]]) {
startAfterValue = [FNextPushId successor:startAfterValue];
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when this is not true? Looks like we just call queryStartingAtInternal with the original value, which doesn't seem to do any validation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case is covered by validateQueryEndpointsForParams:

https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseDatabase/Sources/Api/FIRDatabaseQuery.m#L106-L107

This is called in queryingStartingAtInternal.

@jmwski jmwski assigned schmidt-sebastian and unassigned jmwski Jan 29, 2021

@schmidt-sebastian schmidt-sebastian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the error message.

Can you add a Changelog entry before submitting?

@"than string in combination with queryOrderedByKey"];
format:@"Can't use queryStartingAtValue: or "
@"queryStartingAfterValue: "
@"with other types than string in combination with "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be easier to understand if it said "with non-string types when used with queryOrderedByKey:"

Comment thread FirebaseDatabase/Sources/Core/FRepo.m Outdated
excludeWriteIds:@[]];
if (![node isEmpty]) {
id<FNode> node = [self.serverSyncTree getServerValue:[query querySpec]];
if (node != nil && ![node isEmpty]) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schmidt-sebastian I'm stuck here. I can't figure out why [node isEmpty] is needed to pass the two tests:

https://github.com/firebase/firebase-ios-sdk/pull/7403/files#diff-3a8cb26bda8f6a6d6700b7c2ee8b1368a1c147ed7bb29743a0f6146c08d7b723R1437-R1495

The equivalent is not needed for the android changes.

@google-oss-bot

google-oss-bot commented Feb 3, 2021

Copy link
Copy Markdown
Collaborator

Coverage Report

Affected SDKs

  • FirebaseDatabase-ios-FirebaseDatabase.framework

    SDK overall coverage changed from ? (11826f1) to 56.81% (b210963) by ?.

    Click to show coverage changes in 103 files.
    Filename Base (11826f1) Head (b210963) Diff
    APLevelDB.mm ? 61.56% ?
    FAckUserWrite.m ? 83.78% ?
    FArraySortedDictionary.m ? 97.60% ?
    FAtomicNumber.m ? 100.00% ?
    FAuthTokenProvider.m ? 73.53% ?
    FCacheNode.m ? 100.00% ?
    FCachePolicy.m ? 17.14% ?
    FCancelEvent.m ? 0.00% ?
    FChange.m ? 88.24% ?
    FChildChangeAccumulator.m ? 65.22% ?
    FChildEventRegistration.m ? 0.00% ?
    FChildrenNode.m ? 90.93% ?
    FClock.m ? 100.00% ?
    FCompoundHash.m ? 97.92% ?
    FCompoundWrite.m ? 91.45% ?
    FConnection.m ? 27.56% ?
    FDataEvent.m ? 28.57% ?
    FEmptyNode.m ? 100.00% ?
    FEventEmitter.m ? 0.00% ?
    FEventGenerator.m ? 95.69% ?
    FEventRaiser.m ? 33.33% ?
    FIRDataSnapshot.m ? 89.86% ?
    FIRDatabase.m ? 14.98% ?
    FIRDatabaseComponent.m ? 17.39% ?
    FIRDatabaseConfig.m ? 60.38% ?
    FIRDatabaseQuery.m ? 4.13% ?
    FIRDatabaseReference.m ? 6.47% ?
    FIRMutableData.m ? 75.51% ?
    FIRNoopAuthTokenProvider.m ? 0.00% ?
    FIRRetryHelper.m ? 88.37% ?
    FIRServerValue.m ? 0.00% ?
    FIRTransactionResult.m ? 0.00% ?
    FImmutableSortedDictionary.m ? 31.03% ?
    FImmutableSortedSet.m ? 54.22% ?
    FImmutableTree.m ? 85.54% ?
    FIndex.m ? 91.67% ?
    FIndexedFilter.m ? 96.60% ?
    FIndexedNode.m ? 97.14% ?
    FKeepSyncedEventRegistration.m ? 0.00% ?
    FKeyIndex.m ? 62.16% ?
    FLLRBEmptyNode.m ? 75.00% ?
    FLLRBValueNode.m ? 86.01% ?
    FLeafNode.m ? 85.00% ?
    FLevelDBStorageEngine.m ? 73.55% ?
    FLimitedFilter.m ? 95.63% ?
    FListenComplete.m ? 0.00% ?
    FMaxNode.m ? 60.61% ?
    FMerge.m ? 88.10% ?
    FNamedNode.m ? 63.38% ?
    FNextPushId.m ? 63.30% ?
    FOperationSource.m ? 89.29% ?
    FOverwrite.m ? 81.48% ?
    FPath.m ? 94.04% ?
    FPathIndex.m ? 87.80% ?
    FPendingPut.m ? 0.00% ?
    FPersistenceManager.m ? 58.93% ?
    FPersistentConnection.m ? 22.30% ?
    FPriorityIndex.m ? 87.01% ?
    FPruneForest.m ? 90.80% ?
    FQueryParams.m ? 96.59% ?
    FQuerySpec.m ? 87.76% ?
    FRangeMerge.m ? 94.69% ?
    FRangedFilter.m ? 90.36% ?
    FRepo.m ? 13.73% ?
    FRepoInfo.m ? 73.15% ?
    FRepoManager.m ? 30.20% ?
    FSRWebSocket.m ? 39.84% ?
    FServerValues.m ? 49.21% ?
    FSnapshotHolder.m ? 100.00% ?
    FSnapshotUtilities.m ? 62.14% ?
    FSparseSnapshotTree.m ? 97.41% ?
    FStringUtilities.m ? 74.42% ?
    FSyncPoint.m ? 87.31% ?
    FSyncTree.m ? 72.26% ?
    FTrackedQuery.m ? 75.76% ?
    FTrackedQueryManager.m ? 90.40% ?
    FTransformedEnumerator.m ? 100.00% ?
    FTree.m ? 5.92% ?
    FTreeNode.m ? 100.00% ?
    FTreeSortedDictionary.m ? 96.42% ?
    FTreeSortedDictionaryEnumerator.m ? 100.00% ?
    FTupleNodePath.m ? 0.00% ?
    FTupleObjectNode.m ? 0.00% ?
    FTuplePathValue.m ? 100.00% ?
    FTupleRemovedQueriesEvents.m ? 100.00% ?
    FTupleSetIdPath.m ? 0.00% ?
    FTupleStringNode.m ? 0.00% ?
    FTupleTransaction.m ? 0.00% ?
    FTupleUserCallback.m ? 0.00% ?
    FUtilities.m ? 74.61% ?
    FValidation.m ? 26.42% ?
    FValueEventRegistration.m ? 0.00% ?
    FValueIndex.m ? 49.28% ?
    FView.m ? 80.31% ?
    FViewCache.m ? 100.00% ?
    FViewProcessor.m ? 91.66% ?
    FViewProcessorResult.m ? 100.00% ?
    FWebSocketConnection.m ? 40.16% ?
    FWriteRecord.m ? 46.24% ?
    FWriteTree.m ? 75.63% ?
    FWriteTreeRef.m ? 100.00% ?
    NSData+SRB64Additions.m ? 85.71% ?
    fbase64.c ? 28.92% ?

Test Logs

@schmidt-sebastian schmidt-sebastian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have do debug the [node isEmpty] issue, but it looks like the SDK doesn't read from cache when it should.

Comment thread FirebaseDatabase/Sources/Core/FSyncPoint.m Outdated
Comment thread FirebaseDatabase/Sources/Core/FSyncTree.m Outdated
Comment thread FirebaseDatabase/Sources/Core/FSyncTree.m Outdated
Comment thread FirebaseDatabase/Sources/Core/FSyncTree.m Outdated
Comment thread FirebaseDatabase/Tests/Integration/FIRDatabaseQueryTests.m
Comment thread FirebaseDatabase/Tests/Integration/FIRDatabaseQueryTests.m Outdated
Comment thread FirebaseDatabase/Tests/Integration/FIRDatabaseQueryTests.m
@jmwski
jmwski merged commit 6db2e0d into master Feb 10, 2021
@jmwski
jmwski deleted the jw/orderbykey-start-after branch February 10, 2021 17:42
@jmwski jmwski assigned jmwski and unassigned schmidt-sebastian Feb 25, 2021
@firebase firebase locked and limited conversation to collaborators Mar 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants