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

feat(search-indexer): Nested document resolution #15949

Merged
merged 27 commits into from
Sep 19, 2024

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Sep 10, 2024

Nested document resolution

What

  • Rework how we resolve nested entries to root entries during the cms sync process in Elasticsearch.

  • Instead of fetching the hierarchy from Contentful we instead store the hierarchy in Elasticsearch via tags.

  • Each root document is tagged with the id's of its children so we can know what needs to be re-indexed in case of an update to a nested entry

Rework also how we fetch data during initial sync (when all data gets requested from Contentful).

Now we call the sync endpoint to get the sync token and then simply call Contentful ourselves to fetch all indexable content types.
(Previously all data was fetched from the sync api, meaning that we were also getting nested content types which we ignored)

A Quick test locally suggests that the re-sync process is now twice as fast since it now takes about 15 minutes and used to take 30-ish minutes

Why

  • The current approach isn't scalable and relies on loads of network calls to Contentful in order to fetch the hierarchy
  • This new approach significantly reduces the amount of network calls to Contentful and provides a faster look up time

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

@coderabbitai: ignore

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced asynchronous methods for improved synchronization token retrieval and paginated data handling.
    • Enhanced handling of deleted assets during synchronization processes.
    • Added a new optional method to the ContentSearchImporter interface for better synchronization control.
  • Bug Fixes

    • Improved error handling and performance during data synchronization.
  • Documentation

    • Enhanced logging for clearer insights into synchronization operations.

These changes collectively improve the efficiency, clarity, and maintainability of the content management system's synchronization processes.

Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Walkthrough

The changes introduce new asynchronous methods to enhance the synchronization processes within the CmsSyncService, ContentfulService, and IndexingService classes. These modifications include improved handling of pagination and nested entries, as well as the ability to fetch synchronization tokens concurrently. Additionally, a new optional method for retrieving synchronization tokens has been added to the ContentSearchImporter interface, facilitating better management of synchronization states.

Changes

File Path Change Summary
libs/cms/src/lib/search/cmsSync.service.ts Added an asynchronous method getNextSyncToken to retrieve the next synchronization token from Contentful, implementing pagination logic.
libs/cms/src/lib/search/contentful.service.ts Introduced getContentfulDataPaginated for paginated data retrieval and refactored synchronization logic to include deletedAssets. Added a private method resolveNestedEntries for handling nested entries efficiently.
libs/content-search-indexer/src/lib/indexing.service.ts Restructured the doSync method to use Promise.all for concurrently retrieving the next sync token while processing the synchronization loop, improving asynchronous handling.
libs/content-search-indexer/types/src/index.ts Added an optional method getNextSyncToken to the ContentSearchImporter interface, allowing implementers to retrieve a synchronization token asynchronously.

Suggested labels

automerge

Suggested reviewers

  • RunarVestmann
  • oddsson
  • Toti91
  • disaerna

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 7.52688% with 172 lines in your changes missing coverage. Please review.

Project coverage is 36.73%. Comparing base (92485f0) to head (e522ec3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
libs/cms/src/lib/search/contentful.service.ts 0.00% 77 Missing ⚠️
libs/cms/src/lib/search/importers/utils.ts 4.00% 24 Missing ⚠️
libs/cms/src/lib/search/cmsSync.service.ts 0.00% 10 Missing ⚠️
...s/cms/src/lib/search/importers/teamList.service.ts 22.22% 7 Missing ⚠️
...ms/src/lib/search/importers/projectPage.service.ts 14.28% 6 Missing ⚠️
...src/lib/search/importers/serviceWebPage.service.ts 14.28% 6 Missing ⚠️
...cms/src/lib/search/importers/customPage.service.ts 25.00% 3 Missing ⚠️
libs/cms/src/lib/search/importers/event.service.ts 0.00% 3 Missing ⚠️
...rc/lib/search/importers/genericListItem.service.ts 0.00% 3 Missing ⚠️
...ibs/cms/src/lib/search/importers/manual.service.ts 25.00% 3 Missing ⚠️
... and 14 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #15949      +/-   ##
==========================================
- Coverage   36.73%   36.73%   -0.01%     
==========================================
  Files        6735     6734       -1     
  Lines      138324   138379      +55     
  Branches    39347    39353       +6     
==========================================
+ Hits        50814    50831      +17     
- Misses      87510    87548      +38     
Flag Coverage Δ
api 3.39% <ø> (ø)
api-domains-auth-admin 49.89% <ø> (ø)
api-domains-communications 40.00% <7.52%> (-0.46%) ⬇️
application-system-api 41.52% <7.52%> (-0.11%) ⬇️
application-template-api-modules 23.47% <ø> (+0.01%) ⬆️
cms 0.43% <0.53%> (+<0.01%) ⬆️
cms-translations 39.13% <7.52%> (-0.47%) ⬇️
content-search-toolkit 8.50% <ø> (ø)
judicial-system-api 19.40% <ø> (ø)
judicial-system-backend 54.89% <7.52%> (-0.34%) ⬇️
services-user-notification 47.17% <7.52%> (-0.43%) ⬇️
web 1.85% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...cms/src/lib/search/importers/anchorPage.service.ts 20.68% <0.00%> (-1.54%) ⬇️
...bs/cms/src/lib/search/importers/article.service.ts 6.18% <0.00%> (-0.14%) ⬇️
.../src/lib/search/importers/enhancedAsset.service.ts 19.23% <33.33%> (+1.83%) ⬆️
.../cms/src/lib/search/importers/frontpage.service.ts 16.66% <33.33%> (+1.85%) ⬆️
...ms/src/lib/search/importers/groupedMenu.service.ts 22.72% <33.33%> (+1.67%) ⬆️
.../src/lib/search/importers/lifeEventPage.service.ts 23.07% <0.00%> (-1.93%) ⬇️
libs/cms/src/lib/search/importers/link.service.ts 22.72% <33.33%> (+1.67%) ⬆️
libs/cms/src/lib/search/importers/menu.service.ts 22.72% <33.33%> (+1.67%) ⬆️
...c/lib/search/importers/organizationPage.service.ts 20.83% <33.33%> (+1.78%) ⬆️
...ib/search/importers/organizationSubpage.service.ts 17.14% <0.00%> (-1.04%) ⬇️
... and 14 more

... and 41 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 92485f0...e522ec3. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 10, 2024

Datadog Report

All test runs e3406d5 🔗

12 Total Test Services: 0 Failed, 11 Passed
🔻 Test Sessions change in coverage: 5 decreased, 1 increased (+0.01%), 24 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 13.65s 1 no change Link
api-domains-communications 0 0 0 5 0 31.96s 1 decreased (-0.53%) Link
api-domains-license-service 0 0 0 0 0 620.89ms 1 no change Link
application-system-api 0 0 0 111 2 3m 26.71s 1 decreased (-0.04%) Link
application-template-api-modules 0 0 0 109 0 1m 48.91s 1 no change Link
cms-translations 0 0 0 3 0 28.97s 1 decreased (-0.55%) Link
content-search-toolkit 0 0 0 4 0 10.68s 1 no change Link
judicial-system-api 0 0 0 57 0 6.03s 1 no change Link
judicial-system-backend 0 0 0 20954 0 19m 30.7s 1 decreased (-0.32%) Link

🔻 Code Coverage Decreases vs Default Branch (5)

  • cms-translations - jest 48.68% (-0.55%) - Details
  • api-domains-communications - jest 49.25% (-0.53%) - Details
  • judicial-system-backend - jest 58.3% (-0.32%) - Details
  • services-user-notification - jest 69.86% (-0.3%) - Details
  • application-system-api - jest 37.09% (-0.04%) - Details

@RunarVestmann RunarVestmann marked this pull request as ready for review September 17, 2024 16:47
@RunarVestmann RunarVestmann requested review from a team as code owners September 17, 2024 16:47
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 26

Outside diff range and nitpick comments (8)
libs/cms/src/lib/search/importers/link.service.ts (1)

30-30: Add Explicit Type Annotation to childEntryIds

To enhance type safety and code readability, consider adding an explicit type annotation to childEntryIds.

For example:

const childEntryIds: string[] = extractChildEntryIds(entry)
libs/cms/src/lib/search/importers/vacancy.service.ts (1)

Line range hint 30-45: Ensure Effective Tree-Shaking and Bundling

As this file is part of the libs directory, confirm that the added code and imports promote effective tree-shaking and bundling practices to avoid increasing bundle sizes unnecessarily.

libs/cms/src/lib/search/importers/serviceWebPage.service.ts (1)

31-38: Ensure consistent use of optional chaining

In the condition, optional chaining is used to safely access nested properties:

entry.fields?.organization?.fields?.slug

However, in the object literal, the access omits optional chaining:

key: entry.fields.organization.fields.slug,

While the prior check ensures the existence of these properties, using optional chaining consistently enhances code readability and guards against future changes that might introduce null or undefined values.

Consider updating the code as follows:

- key: entry.fields.organization.fields.slug,
+ key: entry.fields?.organization?.fields?.slug,
libs/cms/src/lib/search/importers/teamList.service.ts (1)

24-25: Consider Using Date.now() for Timestamp

Instead of new Date().getTime(), you can use Date.now() to obtain the current timestamp in milliseconds. It makes the code slightly more concise.

Apply the following change:

-const dateUpdated = new Date().getTime().toString()
+const dateUpdated = Date.now().toString()
libs/cms/src/lib/search/importers/event.service.ts (1)

63-71: Consider defining a TypeScript interface for the tags array elements

Defining a specific interface for the objects within the tags array can enhance type safety and improve code readability. This aligns with the project's guidelines for TypeScript usage in defining and exporting types.

libs/cms/src/lib/search/importers/manual.service.ts (1)

80-88: Consider simplifying the code with the spread operator

To improve readability and conciseness, you can use the spread operator combined with map to add the child entry ID tags.

Apply this diff:

 const childEntryIds = extractChildEntryIds(entry)
-for (const id of childEntryIds) {
-  tags.push({
-    key: id,
-    type: 'hasChildEntryWithId',
-  })
-}
+tags.push(
+  ...childEntryIds.map((id) => ({
+    key: id,
+    type: 'hasChildEntryWithId',
+  })),
+)
libs/cms/src/lib/search/importers/utils.ts (2)

245-245: Correct typo in comment

In the comment, "The root node is not it's own child," "it's" should be "its" to indicate possession.

Apply this diff to fix the typo:

           value !== rootNode.sys.id // The root node is not it's own child
+          value !== rootNode.sys.id // The root node is not its own child

221-261: Consider adding unit tests for extractChildEntryIds

Given the recursive nature and complexity of extractChildEntryIds, adding unit tests would help ensure its correctness and handle edge cases effectively.

Do you want me to help generate unit tests for this function or open a GitHub issue to track this task?

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4c8d8d1 and 5aed594.

Files selected for processing (23)
  • libs/cms/src/lib/search/contentful.service.ts (6 hunks)
  • libs/cms/src/lib/search/importers/anchorPage.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/article.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/customPage.service.ts (2 hunks)
  • libs/cms/src/lib/search/importers/enhancedAsset.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/event.service.ts (2 hunks)
  • libs/cms/src/lib/search/importers/frontpage.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/genericListItem.service.ts (2 hunks)
  • libs/cms/src/lib/search/importers/groupedMenu.service.ts (2 hunks)
  • libs/cms/src/lib/search/importers/lifeEventPage.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/link.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/manual.service.ts (2 hunks)
  • libs/cms/src/lib/search/importers/menu.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/news.service.ts (2 hunks)
  • libs/cms/src/lib/search/importers/organizationPage.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/organizationSubpage.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/projectPage.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/serviceWebPage.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/subArticle.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/supportQNA.service.ts (2 hunks)
  • libs/cms/src/lib/search/importers/teamList.service.ts (3 hunks)
  • libs/cms/src/lib/search/importers/utils.ts (1 hunks)
  • libs/cms/src/lib/search/importers/vacancy.service.ts (3 hunks)
Additional context used
Path-based instructions (23)
libs/cms/src/lib/search/importers/link.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/groupedMenu.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/vacancy.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/menu.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/organizationPage.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/projectPage.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/serviceWebPage.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/enhancedAsset.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/lifeEventPage.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/anchorPage.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/customPage.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/teamList.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/frontpage.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/genericListItem.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/event.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/organizationSubpage.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/news.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/manual.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/subArticle.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/supportQNA.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/utils.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/importers/article.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/contentful.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Additional comments not posted (36)
libs/cms/src/lib/search/importers/link.service.ts (2)

8-8: Importing extractChildEntryIds Utility Function

The import statement correctly adds extractChildEntryIds from the utils module, enabling the extraction of child entry IDs for tagging purposes.


40-43: Constructing the tags Array Appropriately

The tags array is correctly constructed by mapping over childEntryIds. This facilitates efficient lookup of documents by their child entries.

libs/cms/src/lib/search/importers/groupedMenu.service.ts (2)

9-9: Importing 'extractChildEntryIds' utility function looks good.

The import statement correctly includes extractChildEntryIds from './utils', which is necessary for extracting child entry IDs.


31-31: Consider handling entries with no child IDs.

Ensure that extractChildEntryIds(entry) handles cases where an entry might not have any child entries. This will prevent potential issues when mapping over an empty array.

libs/cms/src/lib/search/importers/vacancy.service.ts (1)

8-8: Confirm Import Path and Export of 'extractChildEntryIds'

Ensure that the './utils' module correctly exports extractChildEntryIds and that the import path is accurate relative to vacancy.service.ts.

libs/cms/src/lib/search/importers/menu.service.ts (3)

8-8: Importing extractChildEntryIds enhances modularity and reusability.

The addition of extractChildEntryIds from './utils' promotes code reusability and keeps the MenuSyncService focused on its primary responsibility.


29-29: Efficient extraction of child entry IDs for tagging.

Using extractChildEntryIds(entry) effectively retrieves the IDs of child entries, which enhances the tagging mechanism for better tracking and resolution of nested documents.


41-44: Properly mapping child entry IDs into tags array.

The spread operator with childEntryIds.map correctly adds tags for each child ID, associating them with the type 'hasChildEntryWithId'. This approach improves the search indexer's ability to handle nested content structures.

libs/cms/src/lib/search/importers/organizationPage.service.ts (2)

8-8: Import of 'extractChildEntryIds' is appropriate

The addition of extractChildEntryIds import aligns with the new functionality and is correctly implemented.


32-34: Ensure 'extractChildEntryIds' handles entries without children

Verify that extractChildEntryIds gracefully handles cases where an entry has no child entries, returning an empty array without errors.

libs/cms/src/lib/search/importers/projectPage.service.ts (2)

29-36: Good conditional initialization of 'tags'

The code correctly initializes the tags array based on the presence of entry.fields.slug, ensuring that the slug tag is added only when available.


8-8: Verify that 'extractChildEntryIds' is properly exported

Ensure that the extractChildEntryIds function is correctly exported from the utils module to prevent import errors.

Run the following script to verify the export:

libs/cms/src/lib/search/importers/serviceWebPage.service.ts (2)

8-8: Good use of utility function for extracting child entry IDs

Importing extractChildEntryIds from the utils module enhances code reusability and maintainability. This aligns with the project's emphasis on reusability of components and hooks across different NextJS apps.


41-47: Verify that 'extractChildEntryIds' handles entries without children

Ensure that the extractChildEntryIds(entry) function correctly handles cases where an entry might not have child entries, returning an empty array when appropriate. This prevents potential runtime errors when iterating over childEntryIds.

You can confirm the function's behavior with the following test:

Verification successful

extractChildEntryIds correctly handles entries without children

The implementation of extractChildEntryIds is robust and properly handles cases where an entry might not have child entries. It initializes an empty array childIds and only adds IDs when valid child entries are found. If no children are present, the function will naturally return an empty array, preventing potential runtime errors when iterating over childEntryIds.

Key points:

  • The function uses a recursive approach to explore all nested structures.
  • It includes checks for null/undefined values and avoids circular references.
  • Child IDs are only added when specific conditions are met (sys.id that's not the root node's ID).

No changes are required as the current implementation is safe and efficient.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that 'extractChildEntryIds' returns an empty array for entries without children.

# Test: Search for the implementation of 'extractChildEntryIds' and check its return value.
ast-grep --lang typescript --pattern $'function extractChildEntryIds($_) {
  $$$
}'

Length of output: 84


Script:

#!/bin/bash
# Search for extractChildEntryIds using ripgrep
rg "extractChildEntryIds" -n

# Use a more flexible ast-grep pattern to find the function implementation
ast-grep --lang typescript --pattern "extractChildEntryIds = $_"

# Look for the file where extractChildEntryIds is used
rg "extractChildEntryIds\(" -n libs/cms/src/lib/search/importers/serviceWebPage.service.ts

Length of output: 5152


Script:

#!/bin/bash
# Display the content of the extractChildEntryIds function
sed -n '/export const extractChildEntryIds/,/^}/p' libs/cms/src/lib/search/importers/utils.ts

Length of output: 189


Script:

#!/bin/bash
# Display the content of the extractChildEntryIds function using ripgrep
rg -A 30 "export const extractChildEntryIds" libs/cms/src/lib/search/importers/utils.ts

Length of output: 911

libs/cms/src/lib/search/importers/enhancedAsset.service.ts (2)

8-8: Ensure extractChildEntryIds is correctly exported and bundled

The extractChildEntryIds function is imported from './utils'. Please verify that this utility function is properly exported in the utils module and that it will be included in the build process for effective tree-shaking and bundling practices.


54-57: Confirm the format of tags for child entries

Ensure that the structure of the tags generated for childEntryIds aligns with the expected schema. Specifically, verify that the key and type properties are correctly used and that downstream services correctly interpret the hasChildEntryWithId type.

libs/cms/src/lib/search/importers/lifeEventPage.service.ts (2)

13-13: Importing 'extractChildEntryIds' Utility Function

The import statement for extractChildEntryIds is correct, promoting code reusability and maintainability.


53-56: Correctly Mapping 'childEntryIds' to 'tags'

The mapping of childEntryIds to the tags array is implemented correctly, enhancing document metadata and facilitating better tracking of parent-child relationships.

libs/cms/src/lib/search/importers/anchorPage.service.ts (2)

40-42: Child Entry IDs are correctly extracted and assigned

The extraction of child entry IDs using extractChildEntryIds(entry) and assigning them to childEntryIds enhances the document's metadata for future lookups of child documents.


54-57: Tags field appropriately incorporates child entry IDs

Mapping the childEntryIds to the tags array with the specified structure correctly facilitates tracking relationships between entries, aligning with the intended functionality.

libs/cms/src/lib/search/importers/customPage.service.ts (2)

8-8: Import statement for 'extractChildEntryIds' is correct

The import of extractChildEntryIds from './utils' is appropriate and aligns with module usage practices.


54-62: Verify usage of 'hasChildEntryWithId' tags in the system

Ensure that the hasChildEntryWithId tag type is correctly handled in the indexing and search processes to enable nested document resolution as intended.

Run the following script to locate where hasChildEntryWithId is used in the codebase:

Consider reviewing and updating the indexing and search logic to ensure that documents tagged with hasChildEntryWithId are effectively associated with their child entries during search operations.

libs/cms/src/lib/search/importers/teamList.service.ts (2)

2-3: Appropriate Import Statements

The necessary modules and types are correctly imported, ensuring proper functionality.


6-7: Proper Use of TypeScript Types and Utilities

Good use of TypeScript types and utility functions to enhance code clarity and reusability.

libs/cms/src/lib/search/importers/frontpage.service.ts (2)

8-8: Importing extractChildEntryIds utility function

The import statement correctly includes the extractChildEntryIds function from './utils'.


61-64: Verify that childEntryIds is always an array before mapping

To ensure safe execution of the map function, confirm that childEntryIds is always an array. If there's a possibility it could be undefined or null, the map method would throw an error.

Run the following script to check the return type of extractChildEntryIds:

Verification successful

Verification: childEntryIds is consistently an array

Based on the implementation of extractChildEntryIds in utils.ts and its usage across multiple services, we can confirm that childEntryIds is always an array. The function initializes an empty string[] array and populates it through recursive traversal. While an explicit return type annotation would have been clearer, the consistent usage of .map() on the result across various services strongly indicates that it always returns an array.

Given this implementation, the current usage in frontpage.service.ts is safe:

...childEntryIds.map((id) => ({
  key: id,
  type: 'hasChildEntryWithId',
})),

No additional safeguards are necessary in this case.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if `extractChildEntryIds` always returns an array.

# Expected result: Function should always return an array type.

# Search for the function definition and inspect its return type.
rg --type ts -A 5 -B 2 'function extractChildEntryIds' 

# Alternatively, if using TypeScript types:
rg --type ts 'extractChildEntryIds.*:.*\[\]'

Length of output: 103


Script:

#!/bin/bash
# Search for childEntryIds in TypeScript files
rg --type ts 'childEntryIds'

# Look for similar function names related to extracting child entry IDs
rg --type ts 'extract.*ChildEntry.*'

# Check for imports in the file where childEntryIds is used
rg --type ts -A 10 'import.*from' libs/cms/src/lib/search/importers/frontpage.service.ts

Length of output: 10253


Script:

#!/bin/bash
# Examine the implementation of extractChildEntryIds in utils.ts
rg --type ts -A 20 'export const extractChildEntryIds' libs/cms/src/lib/search/importers/utils.ts

# Check for any type annotations or safeguards
rg --type ts 'extractChildEntryIds.*:.*\[\]' libs/cms/src/lib/search/importers/utils.ts

Length of output: 692

libs/cms/src/lib/search/importers/genericListItem.service.ts (1)

9-9: Confirmed: 'extractChildEntryIds' import added correctly

The import statement now includes extractChildEntryIds, ensuring the function is available for use.

libs/cms/src/lib/search/importers/organizationSubpage.service.ts (3)

12-12: Importing 'extractChildEntryIds' is appropriate.

The addition of extractChildEntryIds to the imports ensures that the utility function is available for use in the code below.


52-55: Correct extraction of child entry IDs for tagging.

The code correctly extracts child entry IDs from the entry using extractChildEntryIds(entry). This enhances the document's metadata by allowing future lookups to determine parent-child relationships.


75-78: Properly tagging documents with child entry IDs.

Including the child entry IDs in the tags array ensures that each document is associated with its children. This is essential for maintaining accurate relationships within the search index.

libs/cms/src/lib/search/importers/news.service.ts (1)

13-13: Import statement added appropriately.

The import of extractChildEntryIds from ./utils is correctly added and integrates well with the existing imports.

libs/cms/src/lib/search/importers/manual.service.ts (1)

14-14: Import statement approved

The import of extractChildEntryIds from './utils' is correct and ensures the necessary functionality is included.

libs/cms/src/lib/search/importers/subArticle.service.ts (2)

14-14: Import statement for extractChildEntryIds is appropriate

The addition of extractChildEntryIds to the imports is necessary for its usage below.


90-92: Ensure extractChildEntryIds handles entries without child entries

Verify that extractChildEntryIds(entry) correctly handles cases where an entry may not have child entries and returns an empty array in such cases to prevent potential errors during mapping.

libs/cms/src/lib/search/importers/supportQNA.service.ts (1)

15-15: LGTM!

The import statement for extractChildEntryIds is correctly added, enhancing the utility functions available.

libs/cms/src/lib/search/importers/article.service.ts (1)

18-18: Importing extractChildEntryIds

The extractChildEntryIds function is imported correctly from './utils', ensuring that the utility is available for use in the service.

libs/cms/src/lib/search/importers/utils.ts Outdated Show resolved Hide resolved
libs/cms/src/lib/search/contentful.service.ts Outdated Show resolved Hide resolved
libs/cms/src/lib/search/contentful.service.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6f2ee71 and f63bd17.

Files selected for processing (1)
  • libs/cms/src/lib/search/contentful.service.ts (7 hunks)
Additional context used
Path-based instructions (1)
libs/cms/src/lib/search/contentful.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cb1fa87 and 6903488.

Files selected for processing (4)
  • libs/cms/src/lib/search/cmsSync.service.ts (1 hunks)
  • libs/cms/src/lib/search/contentful.service.ts (8 hunks)
  • libs/content-search-indexer/src/lib/indexing.service.ts (1 hunks)
  • libs/content-search-indexer/types/src/index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • libs/cms/src/lib/search/contentful.service.ts
Additional context used
Path-based instructions (3)
libs/content-search-indexer/types/src/index.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/content-search-indexer/src/lib/indexing.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/cms/src/lib/search/cmsSync.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Additional comments not posted (1)
libs/content-search-indexer/types/src/index.ts (1)

44-44: Addition of optional getNextSyncToken method enhances interface

The addition of the optional getNextSyncToken method to the ContentSearchImporter interface increases flexibility, allowing implementations to provide synchronization tokens as needed. The method is properly typed and optional, ensuring backward compatibility with existing implementations.

libs/content-search-indexer/src/lib/indexing.service.ts Outdated Show resolved Hide resolved
libs/cms/src/lib/search/cmsSync.service.ts Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (1)
libs/cms/src/lib/search/contentful.service.ts (1)

Line range hint 278-284: Avoid type casting with as when possible

Casting this.contentfulClient.sync using as reduces type safety. If possible, define the type explicitly or ensure that the Contentful client's typings are correctly extended to accommodate this usage.

Consider defining the method with proper typings to enhance maintainability.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b59f3aa and a3e36bb.

Files selected for processing (1)
  • libs/cms/src/lib/search/contentful.service.ts (8 hunks)
Additional context used
Path-based instructions (1)
libs/cms/src/lib/search/contentful.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Additional comments not posted (3)
libs/cms/src/lib/search/contentful.service.ts (3)

169-170: Avoid using any type for query and error parameters

As previously noted, using any reduces type safety and can introduce bugs. Consider defining more specific types for query and error to enhance code maintainability.

Also applies to: 188-189


195-199: Prevent potential infinite loop when chunkSize becomes zero

This issue was previously identified and remains unresolved. If chunkSize becomes 1, Math.floor(1 / 2) results in 0, which may cause an infinite loop or invalid requests with limit: 0. Ensure that chunkSize does not fall below 1.


537-538: Clarify the comment to accurately reflect code logic

The comment // Remove duplicates might be misleading. The code filters out IDs already present in indexableEntries, effectively excluding entries that have been processed. Consider updating the comment to // Exclude IDs already in indexableEntries for clarity.

libs/cms/src/lib/search/contentful.service.ts Outdated Show resolved Hide resolved
libs/cms/src/lib/search/contentful.service.ts Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
libs/cms/src/lib/search/cmsSync.service.ts (1)

162-180: LGTM!

The getNextSyncToken function correctly handles the synchronization process by:

  • Handling the 'fromLast' syncType as a special case.
  • Fetching all pages until the nextSyncToken is obtained.
  • Updating the nextPageToken in each iteration to handle pagination effectively.
  • Waiting for the final token before returning, ensuring a complete synchronization process.

Consider adding the following enhancements to further improve the function:

  • Add error handling to handle potential errors from the Contentful service.
  • Add logging statements to track the progress of the synchronization process.
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a3e36bb and 9cef2a3.

Files selected for processing (4)
  • libs/cms/src/lib/search/cmsSync.service.ts (1 hunks)
  • libs/cms/src/lib/search/contentful.service.ts (8 hunks)
  • libs/content-search-indexer/src/lib/indexing.service.ts (1 hunks)
  • libs/content-search-indexer/types/src/index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • libs/cms/src/lib/search/contentful.service.ts
  • libs/content-search-indexer/src/lib/indexing.service.ts
  • libs/content-search-indexer/types/src/index.ts
Additional context used
Path-based instructions (1)
libs/cms/src/lib/search/cmsSync.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."

@RunarVestmann RunarVestmann added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Sep 19, 2024
@kodiakhq kodiakhq bot merged commit 5d3444a into main Sep 19, 2024
60 checks passed
@kodiakhq kodiakhq bot deleted the feature/search-indexer-nested-document-resolution branch September 19, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants