Skip to content

Conversation

@danieljbruce
Copy link
Contributor

@danieljbruce danieljbruce commented Oct 31, 2024

Summary:

Currently in the save method, if the user sets excludeLargeProperties to true then some code in this method will extend the excludeFromIndexes list based on the position of large properties in the entity object. This PR refactors all of this code into a separate function called extendExcludeFromIndexes because it allows us to unit test this code to make sure it is working correctly. We cannot unit test this code when it is buried inside the save function like it is right now and it allows us to complete the next steps listed below.

This is a follow-up to this PR.

Next steps:

Next we need to do the following:

  1. Pull the code that creates an entity proto from an entity object currently inside the save function into a separate function so that it can be unit tested. Call this new internal function buildEntityProto.
  2. Write tests to ensure that for any input, whenever extendExcludeFromIndexes is used and then buildEntityProto is used, the resulting entity proto always has excludeFromIndexes: true in all the places of the entity proto where the large properties are.
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: datastore Issues related to the googleapis/nodejs-datastore API. labels Oct 31, 2024
@danieljbruce danieljbruce changed the base branch from main to exclude-from-indexes-cleanup October 31, 2024 19:13
@danieljbruce danieljbruce marked this pull request as ready for review November 1, 2024 14:11
@danieljbruce danieljbruce requested review from a team as code owners November 1, 2024 14:11
@danieljbruce danieljbruce removed the request for review from daniel-sanche November 1, 2024 14:16
@danieljbruce danieljbruce reopened this Nov 1, 2024
@danieljbruce danieljbruce changed the base branch from exclude-from-indexes-cleanup to main November 1, 2024 16:55
@danieljbruce danieljbruce changed the base branch from main to exclude-from-indexes-cleanup November 1, 2024 16:55
* large properties in the entity object. The extended excludeFromIndexes
* list is then used when building the entity proto.
*/
// TODO: Add params

Choose a reason for hiding this comment

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

is this todo still valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just pushed updates to address this. This is about adding documentation for the parameters which is done now.

if (entityObject.excludeLargeProperties) {
if (Array.isArray(entityObject.data)) {
// This code populates the excludeFromIndexes list with the right values.
if (entityObject.excludeLargeProperties) {

Choose a reason for hiding this comment

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

isn't this redundant from line 24?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. I just pushed an update to remove this line.

Copy link

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

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

LGTM

@danieljbruce danieljbruce merged commit d2904ad into exclude-from-indexes-cleanup Nov 5, 2024
12 checks passed
@danieljbruce danieljbruce deleted the 376497482-separate-function-for-adding-large-properties branch November 5, 2024 14:39
danieljbruce added a commit that referenced this pull request Nov 6, 2024
#1356) * fix: The save function should not throw an error for name/value properties in arrays (#1336) * Add some test cases for findLargeProperties_ * Add a test for arrays and skip it. * Add a test for the complex case wrapped in an arra * Add a test case for an array without name/value. * Add another test for name/value pair * Change the test case involving a name/value pair * Add two simple test cases for excludeFromIndexes * Add another unit test for findLargeProperties_ * Remove if block that stops recursion * Add a test for save with a `name/value` pair * Add some test code that ensures name/value encoded Against the current source code, this test fails because the code throws an error, but it should pass. * Add header * Remove only * Add a test that saves a long string value property * Add a unit test checking longString for value * Remove only * TODO is done * refactor: Add separate function for adding large properties to the excludeFromIndexes list (#1349) * Add some test cases for findLargeProperties_ * Add a test for arrays and skip it. * Add a test for the complex case wrapped in an arra * Add a test case for an array without name/value. * Add another test for name/value pair * Change the test case involving a name/value pair * Add two simple test cases for excludeFromIndexes * Add another unit test for findLargeProperties_ * Remove if block that stops recursion * Add a test for save with a `name/value` pair * Add some test code that ensures name/value encoded Against the current source code, this test fails because the code throws an error, but it should pass. * Add header * Remove only * Add a test that saves a long string value property * Add a unit test checking longString for value * Remove only * TODO is done * Refactor the save function Pull out the code that extends the excludeFromIndexes list * Add TODO * Write unit tests for the new excludeFromIndexes fn * Add the header * Document parameter for extendExcludeFromIndexes * Remove redundant check * refactor: Add a separate function for building the entity proto (#1350) * Add some test cases for findLargeProperties_ * Add a test for arrays and skip it. * Add a test for the complex case wrapped in an arra * Add a test case for an array without name/value. * Add another test for name/value pair * Change the test case involving a name/value pair * Add two simple test cases for excludeFromIndexes * Add another unit test for findLargeProperties_ * Remove if block that stops recursion * Add a test for save with a `name/value` pair * Add some test code that ensures name/value encoded Against the current source code, this test fails because the code throws an error, but it should pass. * Add header * Remove only * Add a test that saves a long string value property * Add a unit test checking longString for value * Remove only * TODO is done * Refactor the save function Pull out the code that extends the excludeFromIndexes list * Add TODO * Write unit tests for the new excludeFromIndexes fn * Add the header * Refactor the code for building the entity proto * Rename it buildEntityProto * The tests need another mock due to the structure The structure change requires another mock. * First two tests for buildEntityProto * Reintroduce extendExcludeFromIndexes.ts tests * Adjust the test to match expected proto * Add another test for an entity in an array * Add headers * Add another header * Eliminate space. Simplify diff * test: Ensure that using extendExcludeFromIndexes and then buildEntityProto always excludes large properties from indexing (#1355) * Add some test cases for findLargeProperties_ * Add a test for arrays and skip it. * Add a test for the complex case wrapped in an arra * Add a test case for an array without name/value. * Add another test for name/value pair * Change the test case involving a name/value pair * Add two simple test cases for excludeFromIndexes * Add another unit test for findLargeProperties_ * Remove if block that stops recursion * Add a test for save with a `name/value` pair * Add some test code that ensures name/value encoded Against the current source code, this test fails because the code throws an error, but it should pass. * Add header * Remove only * Add a test that saves a long string value property * Add a unit test checking longString for value * Remove only * TODO is done * Refactor the save function Pull out the code that extends the excludeFromIndexes list * Add TODO * Write unit tests for the new excludeFromIndexes fn * Add the header * Refactor the code for building the entity proto * Rename it buildEntityProto * The tests need another mock due to the structure The structure change requires another mock. * First two tests for buildEntityProto * Reintroduce extendExcludeFromIndexes.ts tests * Adjust the test to match expected proto * Add another test for an entity in an array * Add headers * Add another header * Add some tests for checkEntityProto Make sure that checkEntityProto is working correctly. * Empty commit * Pull out complexCaseEntities * Add a few more tests to excludeIndexesAndBuildProto * Add generated test cases ensuring completeness * Add a few comments that explain behaviour of block * Add comments explaining code blocks * Add a bunch of other generated tests * Make this test more meaningful for name/value chek * Fix the generator * Remove console logs * Add better test name descriptions * Add TODO * Add a comment about the array of arrays test case * Increase the max depth * Add headers to the codebase * Update parameter descriptions * Add a bunch of parameter documentation Correct only as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: datastore Issues related to the googleapis/nodejs-datastore API. size: l Pull request size is large.

3 participants