Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

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

Merged
thebrianchen merged 2 commits into
bc/rc-mainfrom
bc/rd-logs
Mar 29, 2021
Merged

thebrianchen merged 2 commits into
bc/rc-mainfrom
bc/rd-logs

Conversation

@thebrianchen

@thebrianchen thebrianchen commented Mar 22, 2021 •

Copy link
Copy Markdown

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 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

codecov Bot commented Mar 22, 2021 •

Copy link
Copy Markdown

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.

Comment thread dev/test/query.ts
nanos?: number
): protobuf.ITimestamp {
if (seconds === undefined && nanos === undefined) {
return {seconds: '5', nanos: 6};

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread dev/src/reference.ts Outdated
for (const fieldFilter of this._queryOptions.fieldFilters) {
if (FieldPath.documentId().isEqual(fieldFilter.field)) {
hasDocumentId = true;
}

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 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) {
    ...
   }


Comment thread dev/test/query.ts
nanos?: number
): protobuf.ITimestamp {
if (seconds === undefined && nanos === undefined) {
return {seconds: '5', nanos: 6};

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.

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

Comment thread dev/test/query.ts Outdated
queryEqualsWithParent(actual, '', ...protoComponents);
queryEqualsWithParentAndReadTime(
actual,
'',

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 is ''? Can you add a comment?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

2 participants