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: fetch all references with includes #519

Merged
merged 14 commits into from
Mar 26, 2024

Conversation

ChidinmaOrajiaku
Copy link
Contributor

Purpose

Fetch all references with includes

Screen.Recording.2024-03-25.at.09.31.20.mov

With Deep Binding

Screen.Recording.2024-03-25.at.09.33.29.mov

Approach

@ChidinmaOrajiaku ChidinmaOrajiaku requested review from a team as code owners March 25, 2024 08:35
Copy link

vercel bot commented Mar 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
experience-builder-test-app ✅ Ready (Inspect) Visit Preview Mar 26, 2024 1:53pm

@dimitrycf
Copy link
Contributor

Will properly test it after PH, but a quick open question: does it "deduplicate" the includes{} ?

because, I wonder if each page will bring it's own includes{} with let's say asset123 and then in theory if 10 pages bring in asset123 as part of includes{} it will be in final includes{} 10 times?

@ChidinmaOrajiaku
Copy link
Contributor Author

Will properly test it after PH, but a quick open question: does it "deduplicate" the includes{} ?

because, I wonder if each page will bring it's own includes{} with let's say asset123 and then in theory if 10 pages bring in asset123 as part of includes{} it will be in final includes{} 10 times?

This is up to the API, but in theory, I guess your thought is correct.

Copy link
Contributor

@dimitrycf dimitrycf left a comment

Choose a reason for hiding this comment

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

Hey Didi! 👋

As I was trying to understand the algorithm I was making some notes, and noticed that the algorithm can be simplified and certain operations can be made explicit.

Please have a look at this proposal for the refactoring and let me know what you think.

PR #522

Copy link
Contributor

@dimitrycf dimitrycf left a comment

Choose a reason for hiding this comment

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

I have noticed that you intorduced separation between fetchAllEntries() and fetchAllAssets(). I tried that too on Friday (I tried refactoring, but got stuck with wrangling TypeScript types for an hour or so and eventually realized that rolling back was the easier way for a Friday evening solution).

However, now that there are two functions, we have this pretty complicated logic of recursive halving duplicated 😱 that makes me scared!

  } catch (error) {
    if (
      error instanceof Error &&
      error.message.includes('size too big') &&
      limit > MIN_FETCH_LIMIT
    ) {
      const newLimit = Math.max(MIN_FETCH_LIMIT, Math.floor(limit / 2));
      return fetchAllAssets({
        client,
        ids,
        locale,
        skip,
        limit: newLimit,
        responseItems,
      });
    }

    throw error;
  }


expect(mockClient.withoutLinkResolution.getEntries).toHaveBeenCalledTimes(5);
expect(result.includes.Entry).toHaveLength(6);
Copy link
Contributor

@dimitrycf dimitrycf Mar 26, 2024

Choose a reason for hiding this comment

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

It would be great to add a comment as to why we compare with 6, eg.

// Five pages will return those values of `includes.Entry[]` 
// Page 1 : `some-entry-id` , `some-entry-id-0`
// Page 2: `some-entry-id` , `some-entry-id-20`
// Page 3: `some-entry-id` , `some-entry-id-40`
// Page 4: `some-entry-id` , `some-entry-id-60`
// Page 5: `some-entry-id` , `some-entry-id-80`
// But the `result.includes.Entry` is expected to only return unique entries for consistency
// And there are only 6 uniques, as duplicates of `some-entry-id` are not returned or counted
expect(result.includes.Entry).toHaveLength(6);

@dimitrycf
Copy link
Contributor

dimitrycf commented Mar 26, 2024

Copy link
Contributor

@dimitrycf dimitrycf left a comment

Choose a reason for hiding this comment

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

Also would be great to add validation of total count to calls to :

  • fetchAllEntries()
  • fetchAllAssets()

something like this:

const result = await fetchAllEntries(params);
expect(result.items).toHaveLength(100);

Comment on lines 46 to 48
const result = await fetchAllEntries(params);

expect(mockClient.withoutLinkResolution.getEntries).toHaveBeenCalledTimes(5);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add also test for total amount of items eg.

const result = await fetchAllEntries(params);
expect(result.items).toHaveLength(100);

Copy link
Contributor

@dimitrycf dimitrycf left a comment

Choose a reason for hiding this comment

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

APPROVING TO UNBLOCK

(see the comments with suggestions)

@ChidinmaOrajiaku ChidinmaOrajiaku merged commit 962f70b into development Mar 26, 2024
9 checks passed
@ChidinmaOrajiaku ChidinmaOrajiaku deleted the fix/fetch-all-references branch March 26, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants