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

docs: Write javadocs for COUNT API #1783

Merged
merged 13 commits into from Oct 3, 2022
Merged

Conversation

dconeybe
Copy link
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 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 as code owners 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
field.isEqual(otherAggregates[alias])
)
);
// Verify that this object has the same aggregation keys as `other`.
Copy link
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
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

if (!(other instanceof AggregateQuerySnapshot)) {
return false;
}
if (!this.readTime.isEqual(other.readTime)) {
Copy link
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
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
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


const otherData = other._data;
const otherDataKeys: string[] = Object.keys(otherData);
// Verify that this object has the same aggregation keys as `other`.
Copy link
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
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 join this conversation on GitHub. Already have an account? Sign in to comment
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.

None yet

2 participants