Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid adding duplicate orderBys in startAfter() #1453

Merged
merged 2 commits into from Mar 29, 2021

Conversation

thebrianchen
Copy link

@thebrianchen thebrianchen commented Mar 22, 2021

Fixing a bug in recursive delete where invalid queries would be created on stream errors due to adding two orderBy('__name__', ASCENDING) clauses when calling startAfter() (location). The private method createImplicitOrderBy adds an implicit orderBy if there is is no documentId on the fieldOrder fields, but we didn't check the case where the documentId comes from the fieldPaths.

@thebrianchen thebrianchen self-assigned this Mar 22, 2021
@thebrianchen thebrianchen requested review from a team as code owners March 22, 2021 15:55
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Mar 22, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 22, 2021
@codecov
Copy link

codecov bot commented Mar 22, 2021

Codecov Report

Merging #1453 (68a6ef1) into bc/rc-main (f483083) will increase coverage by 0.30%.
The diff coverage is 99.40%.

Impacted file tree graph

@@              Coverage Diff               @@
##           bc/rc-main    #1453      +/-   ##
==============================================
+ Coverage       98.22%   98.52%   +0.30%     
==============================================
  Files              32       32              
  Lines           19565    19684     +119     
  Branches         1372     1303      -69     
==============================================
+ Hits            19217    19393     +176     
+ Misses            344      286      -58     
- Partials            4        5       +1     
Impacted Files Coverage Δ
dev/src/index.ts 97.76% <99.22%> (+2.31%) ⬆️
dev/src/bulk-writer.ts 100.00% <100.00%> (ø)
dev/src/reference.ts 99.89% <100.00%> (+0.68%) ⬆️
dev/src/rate-limiter.ts 98.85% <0.00%> (-1.15%) ⬇️
dev/src/path.ts 98.57% <0.00%> (+0.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cea104...68a6ef1. Read the comment docs.

nanos?: number
): protobuf.ITimestamp {
if (seconds === undefined && nanos === undefined) {
return {seconds: '5', nanos: 6};
Copy link
Author

Choose a reason for hiding this comment

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

We have to cast to seconds since the Timestamp class always converts it to string for some reason. Why do we do this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Proto3 JSON represents int64 as strings, and the seconds component of Timestamps is an int64.

@@ -1521,6 +1521,9 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
// If no explicit ordering is specified, use the first inequality to
// define an implicit order.
for (const fieldFilter of this._queryOptions.fieldFilters) {
if (FieldPath.documentId().isEqual(fieldFilter.field)) {
hasDocumentId = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be cleaner if we ran this in two steps:

    // If no explicit ordering is specified, use the first inequality to
    // define an implicit order.
    if (fieldOrders.length === 0) {
      for (const fieldFilter of this._queryOptions.fieldFilters) {
        if (fieldFilter.isInequalityFilter()) {
          fieldOrders.push(new FieldOrder(fieldFilter.field));
          break;
        }
      }
    }
    
    const hasDocumentId = !!fieldOrders.find(
        fieldOrder => FieldPath.documentId().isEqual(fieldOrder.field));
    if (!hasDocumentId) {
    ...
   }


nanos?: number
): protobuf.ITimestamp {
if (seconds === undefined && nanos === undefined) {
return {seconds: '5', nanos: 6};
Copy link
Contributor

Choose a reason for hiding this comment

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

Proto3 JSON represents int64 as strings, and the seconds component of Timestamps is an int64.

queryEqualsWithParent(actual, '', ...protoComponents);
queryEqualsWithParentAndReadTime(
actual,
'',
Copy link
Contributor

Choose a reason for hiding this comment

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

What is ''? Can you add a comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants