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

docs: Write javadocs for COUNT API#1783

Merged
dconeybe merged 13 commits intotomandersen/countfrom
dconeybe/CountApiDocs
Oct 3, 2022
Merged

docs: Write javadocs for COUNT API#1783
dconeybe merged 13 commits intotomandersen/countfrom
dconeybe/CountApiDocs

Conversation

@dconeybe
Copy link
Copy Markdown
Contributor

@dconeybe dconeybe commented Sep 30, 2022

The wording is (mostly) copied from firebase/firebase-android-sdk#4143, and also partially from firebase/firebase-js-sdk#6632.

There were also some last-minute API and implementation changes:

  1. AggregateField.count() and AggregateField.isEqual() were deleted, since they have no use case until other aggregations are supported (the same change was made in the firebase-js-sdk).
  2. Query._aggregate() was removed, since it was so much simpler to just inline it into Query.count().
  3. Some lint warnings were suppressed with eslint-disable-next-line comments.
  4. AggregateQuery.isEqual() and AggregateQuerySnapshot.isEqual() were tweaked to accommodate the deletion of AggregateField.isEqual().

@dconeybe dconeybe added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Sep 30, 2022
@dconeybe dconeybe self-assigned this Sep 30, 2022
@product-auto-label product-auto-label Bot added the size: l Pull request size is large. label Sep 30, 2022
@dconeybe dconeybe force-pushed the dconeybe/CountApiDocs branch from fdb8d61 to bd210d2 Compare September 30, 2022 03:18
@dconeybe dconeybe changed the base branch from main to tomandersen/count September 30, 2022 03:31
@dconeybe dconeybe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 30, 2022
@dconeybe dconeybe marked this pull request as ready for review September 30, 2022 03:53
@dconeybe dconeybe requested review from a team September 30, 2022 03:53
@dconeybe dconeybe added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Sep 30, 2022
@dconeybe dconeybe removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 30, 2022
Comment thread dev/src/reference.ts Outdated
field.isEqual(otherAggregates[alias])
)
);
// Verify that this object has the same aggregation keys as `other`.
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.

Can we do this without sort? Maybe there exists or we can create a helper method?

The consequence is likely small since we are likely only dealing with maps of one element. So, maybe we can just have a TODO to revisit this when other aggregate types are implement.

https://stackoverflow.com/a/35951373

Copy link
Copy Markdown
Contributor Author

@dconeybe dconeybe Sep 30, 2022

Choose a reason for hiding this comment

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

I looked a little harder (I must have missed this while coding late last night!) and there already exists a deepEqual() function that employs the logic you suggested. So I've modified AggregateQuery.isEqual() and AggregateQuerySnapshot.isEqual() to just use deepEqual().

If interested, here is the raw source code of deepEqual(): https://github.com/epoberezkin/fast-deep-equal/blob/master/src/index.jst, and here is the compiled JavaScript version: https://gist.github.com/dconeybe/c2654f622b87fc0d4c75e5d58364491f

Comment thread dev/src/reference.ts Outdated
if (!(other instanceof AggregateQuerySnapshot)) {
return false;
}
if (!this.readTime.isEqual(other.readTime)) {
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.

The isEquals method for QuerySnapshot does not include timestamp. Are you sure this is correct behavior?

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.

Good point. DocumentSnapshot is actually a better class for comparison than QuerySnapshot, and it indeed explicitly excludes checking the read time:

// Since the read time is different on every document read, we explicitly
// ignore all document metadata in this comparison.

I've removed the comparison of readTime, as suggested, to match the behavior of DocumentSnapshot.isEqual(). I've also updated the documentation, and will make the same fix in the java-firestore SDK. Good catch!

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.

For reference, here is the corresponding fix in the java-firestore SDK: googleapis/java-firestore#1051

Comment thread dev/src/reference.ts Outdated

const otherData = other._data;
const otherDataKeys: string[] = Object.keys(otherData);
// Verify that this object has the same aggregation keys as `other`.
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.

How is this better than previous map comparison?

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.

It's probably not better. I had mistakenly thought that sorting the keys is required. I've changed it to use deepEqual() now.

@dconeybe dconeybe merged commit 996d86e into tomandersen/count Oct 3, 2022
@dconeybe dconeybe deleted the dconeybe/CountApiDocs branch October 3, 2022 15:20
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. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants