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): Move mapping logic to separate class #16410

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Oct 15, 2024

Move mapping logic to separate class

What

  • Now there is a MappingService class that takes care of mapping cms data into elasticsearch data.

  • Instead of writing all resolved root entries from nested entries alongside other entries we now separately write them down to elasticsearch to reduce the memory load

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

Summary by CodeRabbit

  • New Features

    • Introduced the MappingService to enhance content synchronization and mapping capabilities.
    • Updated ContentfulService to improve nested entries resolution with progress tracking.
  • Bug Fixes

    • Simplified CmsSyncService to streamline dependency management and improve data processing.
  • Improvements

    • Enhanced doSync method in CmsSyncService for a more centralized mapping approach.
    • Refined resolveNestedEntries method in ContentfulService for better handling of indexable entries.

@RunarVestmann RunarVestmann added the automerge Merge this PR as soon as all checks pass label Oct 15, 2024
@RunarVestmann RunarVestmann requested review from a team as code owners October 15, 2024 15:05
Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

The changes in this pull request introduce a new MappingService to the CMS synchronization module. This service is integrated into the CmsSyncModule, CmsSyncService, and ContentfulService, replacing previous dependencies and streamlining data mapping processes. The doSync method in CmsSyncService and the resolveNestedEntries method in ContentfulService have been updated to utilize the new mapping approach, enhancing how data is processed during synchronization.

Changes

File Path Change Summary
libs/cms/src/lib/search/cmsSync.module.ts Added MappingService import and included it in the providers array of the @Module decorator.
libs/cms/src/lib/search/cmsSync.service.ts Removed multiple sync service imports, simplified constructor, updated doSync method to use mappingService.mapData.
libs/cms/src/lib/search/contentful.service.ts Injected MappingService into the constructor, updated resolveNestedEntries and getSyncEntries methods for mapping.
libs/cms/src/lib/search/mapping.service.ts Introduced MappingService class with mapData method for processing synchronization data.

Possibly related PRs

Suggested reviewers

  • mannipje

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
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: 7

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

87-92: Specify return type for mapData method

For better readability and maintainability, explicitly declare the return type of the mapData method. This helps with type checking and understanding the method's output.

Apply this diff to specify the return type:

-mapData(entries: processSyncDataInput<unknown>) {
+mapData(entries: processSyncDataInput<unknown>): MappedDataType[] { // Replace MappedDataType with the appropriate type
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c21a58f and e351d23.

📒 Files selected for processing (4)
  • libs/cms/src/lib/search/cmsSync.module.ts (2 hunks)
  • libs/cms/src/lib/search/cmsSync.service.ts (3 hunks)
  • libs/cms/src/lib/search/contentful.service.ts (5 hunks)
  • libs/cms/src/lib/search/mapping.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
libs/cms/src/lib/search/cmsSync.module.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."
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."
libs/cms/src/lib/search/mapping.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 (8)
libs/cms/src/lib/search/cmsSync.module.ts (1)

35-35: LGTM! MappingService successfully integrated.

The changes look good. The MappingService is correctly imported and added to the providers array, making it available for dependency injection within the module. This aligns well with the PR objectives of introducing a new MappingService class to enhance the mapping process of CMS data.

Remember to update the documentation to reflect the addition of this new service and its role in the CMS synchronization process.

Let's verify if the new MappingService affects the module's exports:

This will help us understand if the MappingService needs to be exported from this module for use in other parts of the library.

Also applies to: 73-73

✅ Verification successful

Let's rerun the verification with the corrected file type.


: MappingService is correctly integrated within the cmsSync.module.ts. It is properly imported and provided, ensuring seamless dependency injection for all internal services. No changes to module exports are necessary as MappingService is used exclusively within the library.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if MappingService is used in other files within the library

# Search for MappingService usage
rg --type typescript "MappingService" libs/cms/src/lib/search

Length of output: 96


Script:

#!/bin/bash
# Description: Check if MappingService is used in other files within the library

# Search for MappingService usage in TypeScript files
rg --type ts "MappingService" libs/cms/src/lib/search

Length of output: 667

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

1-28: Imports are well-organized and necessary dependencies are appropriately included

All imported services are correctly specified and align with the dependencies used in the class. There are no unused imports.

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

15-15: Refactoring enhances modularity and reusability

The introduction of MappingService and its integration into CmsSyncService effectively separate the mapping logic from the sync service. This improves modularity and aligns with the coding guidelines by promoting reusability of components across different NextJS apps. It also leverages TypeScript's strengths in defining types and interfaces.

Also applies to: 38-40, 157-157

libs/cms/src/lib/search/contentful.service.ts (5)

27-27: Verify Import Path for MappingService

Ensure that the import path './mapping.service' correctly points to the MappingService module and that it is properly exported.


83-83: Dependency Injection of MappingService

The MappingService is being injected into the constructor and assigned to a private readonly property. This aligns with best practices for dependency injection.


588-593: Proper Mapping Before Bulk Indexing

The data fetched from Contentful is mapped using this.mappingService.mapData(items) before being indexed into Elasticsearch. This ensures that the data conforms to the expected structure.


604-607: Ensure Accurate Nested Entries Progress Logging

The logging statement uses nestedProgress and totalNested to report progress. Verify that nestedProgress is being updated correctly within the loop to reflect the actual number of nested entries processed.


673-673: Confirm Modification of indexableEntries

When calling this.resolveNestedEntries, ensure that any entries added or modified within this method are correctly reflected in indexableEntries, especially if they need to be processed later.

libs/cms/src/lib/search/mapping.service.ts Show resolved Hide resolved
libs/cms/src/lib/search/mapping.service.ts Show resolved Hide resolved
libs/cms/src/lib/search/mapping.service.ts Show resolved Hide resolved
libs/cms/src/lib/search/mapping.service.ts Show resolved Hide resolved
libs/cms/src/lib/search/cmsSync.service.ts Show resolved Hide resolved
libs/cms/src/lib/search/contentful.service.ts Show resolved Hide resolved
libs/cms/src/lib/search/contentful.service.ts Show resolved Hide resolved
Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 76.38889% with 17 lines in your changes missing coverage. Please review.

Project coverage is 36.73%. Comparing base (f560cd2) to head (dbc3b49).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
libs/cms/src/lib/search/contentful.service.ts 15.38% 11 Missing ⚠️
libs/cms/src/lib/search/mapping.service.ts 90.90% 5 Missing ⚠️
libs/cms/src/lib/search/cmsSync.service.ts 66.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16410   +/-   ##
=======================================
  Coverage   36.73%   36.73%           
=======================================
  Files        6808     6809    +1     
  Lines      141069   141087   +18     
  Branches    40219    40227    +8     
=======================================
+ Hits        51818    51825    +7     
- Misses      89251    89262   +11     
Flag Coverage Δ
api 3.37% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.89% <40.27%> (-0.03%) ⬇️
application-system-api 41.42% <76.38%> (-0.01%) ⬇️
application-template-api-modules 27.88% <40.27%> (-0.02%) ⬇️
cms 0.42% <0.00%> (-0.01%) ⬇️
cms-translations 39.02% <40.27%> (-0.03%) ⬇️
judicial-system-api 18.39% <ø> (ø)
judicial-system-backend 55.17% <76.38%> (-0.02%) ⬇️
services-user-notification 46.97% <76.38%> (-0.05%) ⬇️
web 1.82% <ø> (ø)

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

Files with missing lines Coverage Δ
libs/cms/src/lib/search/cmsSync.module.ts 100.00% <100.00%> (ø)
libs/cms/src/lib/search/cmsSync.service.ts 12.12% <66.66%> (-26.81%) ⬇️
libs/cms/src/lib/search/mapping.service.ts 90.90% <90.90%> (ø)
libs/cms/src/lib/search/contentful.service.ts 7.50% <15.38%> (+0.48%) ⬆️

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 f560cd2...dbc3b49. Read the comment docs.

@datadog-island-is
Copy link

Datadog Report

All test runs a5b6789 🔗

10 Total Test Services: 0 Failed, 9 Passed
🔻 Test Sessions change in coverage: 4 decreased, 23 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 3.23s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 14.36s 1 no change Link
api-domains-communications 0 0 0 5 0 33.79s 1 decreased (-0.05%) Link
api-domains-license-service 0 0 0 0 0 581.22ms 1 no change Link
application-system-api 0 0 0 120 2 2m 42.45s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 25.74s 1 no change Link
cms-translations 0 0 0 3 0 27.32s 1 decreased (-0.05%) Link
judicial-system-api 0 0 0 57 0 5.8s 1 no change Link
judicial-system-backend 0 0 0 20973 0 20m 41.63s 1 decreased (-0.03%) Link
services-user-notification 0 0 0 51 0 1m 29.72s 1 decreased (-0.04%) Link

🔻 Code Coverage Decreases vs Default Branch (4)

  • api-domains-communications - jest 49.06% (-0.05%) - Details
  • cms-translations - jest 48.49% (-0.05%) - Details
  • services-user-notification - jest 69.67% (-0.04%) - Details
  • judicial-system-backend - jest 58.58% (-0.03%) - Details

@kodiakhq kodiakhq bot merged commit 4a0a50a into main Oct 15, 2024
59 of 60 checks passed
@kodiakhq kodiakhq bot deleted the feature/search-indexer-seperate-mapping-logic branch October 15, 2024 16:45
@coderabbitai coderabbitai bot mentioned this pull request Nov 13, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants