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

refactor(feed)!: improve structure #35

Merged
merged 13 commits into from
May 14, 2024
Merged

refactor(feed)!: improve structure #35

merged 13 commits into from
May 14, 2024

Conversation

kwaa
Copy link
Member

@kwaa kwaa commented May 14, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new fields hatsu and feed for user feeds.
    • Added UserFeedHatsu and UserFeedItemHatsu for JSON Feed extensions.
  • Bug Fixes

    • Improved handling of image fields in user feeds.
  • Refactor

    • Replaced feed_json, feed_atom, and feed_rss fields with hatsu and feed.
    • Renamed UserFeed to UserFeedTopLevel for better clarity.
    • Updated migration scripts to accommodate new fields and remove deprecated ones.
  • Tests

    • Adjusted test cases to reflect changes from UserFeed to UserFeedTopLevel.
  • Chores

    • Updated dependencies and imports to align with new field names and structures.

@kwaa kwaa added the enhancement New feature or request label May 14, 2024
@kwaa kwaa added this to the 0.2 [celluloid] milestone May 14, 2024
Copy link

coderabbitai bot commented May 14, 2024

Walkthrough

The recent changes streamline the apub crate by consolidating multiple feed fields into a single feed field and introducing hatsu for additional user data. The updates span across several crates, including db_migration, db_schema, and feed, enhancing the flexibility and maintainability of user and feed data structures. These refinements also involve significant restructuring of feed-related code, along with corresponding database migrations to support the new data models.

Changes

Files/Modules Change Summaries
crates/apub/src/actors/db_user.rs, db_user_impl.rs Removed feed_json, feed_atom, feed_rss; added hatsu and feed. Adjusted image field handling. Modified feed retrieval and processing logic.
crates/db_migration/src/... Added new migration modules m20240515_000001_user_feed_hatsu_extension and m20240515_000002_user_feed. Updated User and UserFeedItem enums.
crates/db_schema/src/user.rs, user_feed_item.rs Added FromJsonQueryResult import. Removed old feed fields; added hatsu and feed fields. Introduced UserFeed, UserHatsu, and UserFeedItemHatsu structs with serialization traits.
crates/feed/src/lib.rs, user_feed.rs, user_feed_hatsu.rs Restructured feed-related modules. Introduced UserFeedTopLevel and UserFeedHatsu structs. Added methods for feed retrieval and parsing.
crates/feed/src/user_feed_item.rs, user_feed_item_hatsu.rs Added hatsu field to UserFeedItem. Introduced UserFeedItemHatsu struct with conversion methods.
crates/feed/src/user_feed_top_level.rs Added new methods to UserFeedTopLevel for fetching and parsing feeds.
crates/feed/tests/validate_json_feed.rs, validate_rss_feed.rs Updated tests to reflect changes from UserFeed to UserFeedTopLevel.
crates/scheduler/src/update/job.rs Updated import statements and function calls from UserFeed to UserFeedTopLevel.
crates/db_schema/Cargo.toml Added serde dependency.

🐇
In fields of code, where changes bloom,
We merged the feeds, dispelled the gloom.
With hatsu bright and feed anew,
Our structures strong, our data true.
Through tests and schemas, we did glide,
A rabbit's joy, a coder's pride.
🚀


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

@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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 0ca8e86 and 1da03e9.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (19)
  • crates/apub/src/actors/db_user.rs (2 hunks)
  • crates/apub/src/actors/db_user_impl.rs (3 hunks)
  • crates/db_migration/src/lib.rs (2 hunks)
  • crates/db_migration/src/m20240131_000001_user.rs (2 hunks)
  • crates/db_migration/src/m20240131_000002_user_feed_item.rs (1 hunks)
  • crates/db_migration/src/m20240515_000001_user_feed_hatsu_extension.rs (1 hunks)
  • crates/db_migration/src/m20240515_000002_user_feed.rs (1 hunks)
  • crates/db_schema/Cargo.toml (1 hunks)
  • crates/db_schema/src/user.rs (2 hunks)
  • crates/db_schema/src/user_feed_item.rs (2 hunks)
  • crates/feed/src/lib.rs (1 hunks)
  • crates/feed/src/user_feed.rs (1 hunks)
  • crates/feed/src/user_feed_hatsu.rs (1 hunks)
  • crates/feed/src/user_feed_item.rs (4 hunks)
  • crates/feed/src/user_feed_item_hatsu.rs (1 hunks)
  • crates/feed/src/user_feed_top_level.rs (1 hunks)
  • crates/feed/tests/validate_json_feed.rs (1 hunks)
  • crates/feed/tests/validate_rss_feed.rs (1 hunks)
  • crates/scheduler/src/update/job.rs (3 hunks)
Files skipped from review due to trivial changes (2)
  • crates/db_schema/Cargo.toml
  • crates/scheduler/src/update/job.rs
Additional comments not posted (49)
crates/feed/tests/validate_rss_feed.rs (2)

1-1: Correct usage of UserFeedTopLevel for parsing RSS feeds.


7-7: Ensure that parse_xml_feed correctly handles the provided URL.

Verification successful

The parse_xml_feed method in UserFeedTopLevel correctly handles the provided URL. The method signature and implementation ensure that the URL is parsed and used appropriately, with proper error handling.

  • The method signature is pub async fn parse_xml_feed(feed_url: Url) -> Result<Self, AppError>.
  • The URL is used to make an HTTP GET request, and the response is parsed into a feed using feed_rs.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of `parse_xml_feed` method in `UserFeedTopLevel`.

# Test: Search for the method implementation. Expect: Correct handling of URL parsing.
ast-grep --lang rust --pattern $'impl UserFeedTopLevel {
  $$$
  pub fn parse_xml_feed(url: &str) -> Result<Self, AppError> {
    $$$
  }
  $$$
}'

Length of output: 147



Script:

#!/bin/bash
# Step 1: Verify the existence of the `UserFeedTopLevel` struct or enum.
ast-grep --lang rust --pattern 'struct UserFeedTopLevel { $$$ }' || ast-grep --lang rust --pattern 'enum UserFeedTopLevel { $$$ }'

# Step 2: Search for the `parse_xml_feed` method within the `UserFeedTopLevel` implementation.
ast-grep --lang rust --pattern 'impl UserFeedTopLevel { $$$ pub async fn parse_xml_feed($_) -> Result<$_, $_> { $$$ } $$$ }'

Length of output: 5244

crates/feed/tests/validate_json_feed.rs (2)

1-1: Correct usage of UserFeedTopLevel for parsing JSON feeds.


7-7: Ensure that parse_json_feed correctly handles the provided URL.

Verification successful

parse_json_feed correctly handles the provided URL

The parse_json_feed method in UserFeedTopLevel correctly handles the provided URL by using reqwest::get to fetch the feed and then parsing the response as JSON.

  • File: crates/feed/src/user_feed_top_level.rs
  • Method Implementation:
    pub async fn parse_json_feed(feed_url: Url) -> Result<Self, AppError> {
        Ok(reqwest::get(feed_url).await?.json::<Self>().await?)
    }
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of `parse_json_feed` method in `UserFeedTopLevel`.

# Test: Search for the method implementation. Expect: Correct handling of URL parsing.
ast-grep --lang rust --pattern $'impl UserFeedTopLevel {
  $$$
  pub fn parse_json_feed(url: &str) -> Result<Self, AppError> {
    $$$
  }
  $$$
}'

Length of output: 148



Script:

#!/bin/bash
# Description: Search for the `parse_json_feed` method in the entire codebase and inspect its implementation.

# Search for the `parse_json_feed` method definition.
rg 'fn parse_json_feed'

# If found, display the implementation of the method.
# Assuming the method is found in a file, extract and display the method implementation.
# This is a two-step process: first find the file, then extract the method implementation.
for file in $(rg --files-with-matches 'fn parse_json_feed'); do
  echo "File: $file"
  sed -n '/fn parse_json_feed/,/}/p' $file
done

Length of output: 571

crates/feed/src/lib.rs (3)

2-3: Correctly added new modules user_feed_top_level and user_feed_hatsu.


7-9: Correctly updated public exports to include new structs.


11-11: Ensure that UserFeedItemHatsu is correctly implemented and used.

Verification successful

The UserFeedItemHatsu struct is implemented in two different files with different field types (Url in crates/feed/src/user_feed_item_hatsu.rs and String in crates/db_schema/src/user_feed_item.rs). The conversion between these types appears to be intentional and is handled correctly in the codebase.

  • crates/feed/src/user_feed_item_hatsu.rs: Uses Url and provides a method to convert it to String.
  • crates/db_schema/src/user_feed_item.rs: Uses String directly.

These implementations and their usages are consistent and correct.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of `UserFeedItemHatsu` struct.

# Test: Search for the struct implementation. Expect: Correct fields and methods.
ast-grep --lang rust --pattern $'pub struct UserFeedItemHatsu {
  $$$
}'

Length of output: 465



Script:

#!/bin/bash
# Description: Inspect the full definitions of `UserFeedItemHatsu` structs.

# Display the full struct definitions for further analysis.
echo "Inspecting crates/feed/src/user_feed_item_hatsu.rs:"
sed -n '13,20p' ./crates/feed/src/user_feed_item_hatsu.rs

echo "Inspecting crates/db_schema/src/user_feed_item.rs:"
sed -n '23,30p' ./crates/db_schema/src/user_feed_item.rs

Length of output: 772



Script:

#!/bin/bash
# Description: Verify the usage of `UserFeedItemHatsu` structs in the codebase.

# Search for the usage of `UserFeedItemHatsu` in the codebase.
rg 'UserFeedItemHatsu' --context 5

Length of output: 5862

crates/db_migration/src/lib.rs (2)

10-11: Correctly added new migration modules m20240515_000001_user_feed_hatsu_extension and m20240515_000002_user_feed.


26-27: Correctly included new migrations in the Migrator implementation.

crates/feed/src/user_feed_hatsu.rs (4)

1-2: Ensure that the Deref trait implementation is correct.

Verification successful

The Deref trait implementation for WrappedUserHatsu is correctly targeting DbUserHatsu and the deref method is properly implemented.

  • type Target = DbUserHatsu; is correctly specified.
  • The deref method returns a reference to self.0, which is appropriate.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the `Deref` trait implementation for `WrappedUserHatsu`.

# Test: Search for the `Deref` trait implementation. Expect: Correct target type and method.
ast-grep --lang rust --pattern $'impl Deref for WrappedUserHatsu {
  type Target = DbUserHatsu;
  $$$
}'

Length of output: 514


13-16: Correctly defined UserFeedHatsu struct with appropriate fields.


18-39: Correctly implemented WrappedUserHatsu with necessary traits and methods.


41-48: Ensure that into_db method correctly converts UserFeedHatsu to DbUserHatsu.

Verification successful

The into_db method correctly converts UserFeedHatsu to DbUserHatsu by transforming the about and banner_image fields from Option<Url> to Option<String>.

  • UserFeedHatsu definition:

    pub struct UserFeedHatsu {
        pub about: Option<Url>,
        pub banner_image: Option<Url>,
    }
  • DbUserHatsu (alias UserHatsu) definition:

    pub struct UserHatsu {
        pub about: Option<String>,
        pub banner_image: Option<String>,
    }

The transformation logic in the into_db method is appropriate and correct.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the `into_db` method implementation for `UserFeedHatsu`.

# Test: Search for the `into_db` method implementation. Expect: Correct conversion logic.
ast-grep --lang rust --pattern $'impl UserFeedHatsu {
  pub fn into_db(self) -> DbUserHatsu {
    $$$
  }
}'

Length of output: 684



Script:

#!/bin/bash
# Description: Find and display the definitions of `UserFeedHatsu` and `DbUserHatsu`.

# Search for the definition of `UserFeedHatsu`
ast-grep --lang rust --pattern 'struct UserFeedHatsu { $$$ }'

# Search for the definition of `DbUserHatsu`
ast-grep --lang rust --pattern 'struct DbUserHatsu { $$$ }'

Length of output: 125



Script:

#!/bin/bash
# Description: Find and display the definitions of `UserFeedHatsu` and `DbUserHatsu` using `rg`.

# Search for the definition of `UserFeedHatsu`
rg 'struct UserFeedHatsu'

# Search for the definition of `DbUserHatsu`
rg 'struct DbUserHatsu'

Length of output: 115



Script:

#!/bin/bash
# Description: Find and display the full definitions of `UserFeedHatsu` and `DbUserHatsu`.

# Search for the full definition of `UserFeedHatsu`
rg -A 10 'struct UserFeedHatsu' crates/feed/src/user_feed_hatsu.rs

# Search for the definition of `DbUserHatsu` with a broader pattern
rg 'DbUserHatsu' --type rust

Length of output: 1071



Script:

#!/bin/bash
# Description: Find and display the definition of `UserHatsu` in the `hatsu_db_schema` crate.

# Search for the definition of `UserHatsu` in the `hatsu_db_schema` crate
rg 'struct UserHatsu' --type rust

Length of output: 87



Script:

#!/bin/bash
# Description: Capture the full definition of `UserHatsu` in `crates/db_schema/src/user.rs`.

# Capture the full definition of `UserHatsu`
rg -A 10 'struct UserHatsu' crates/db_schema/src/user.rs

Length of output: 355

crates/feed/src/user_feed_item_hatsu.rs (4)

1-2: Ensure that the Deref trait implementation is correct.

Verification successful

The Deref trait implementation for WrappedUserFeedItemHatsu is correctly defined in crates/feed/src/user_feed_item_hatsu.rs at lines 26-32. The Target type is set to DbUserFeedItemHatsu, and the deref method returns a reference to self.0, which is appropriate.

  • impl Deref for WrappedUserFeedItemHatsu {
  • type Target = DbUserFeedItemHatsu;
  • fn deref(&self) -> &Self::Target { &self.0 }

This implementation appears to be correct and follows the expected pattern for the Deref trait.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the `Deref` trait implementation for `WrappedUserFeedItemHatsu`.

# Test: Search for the `Deref` trait implementation. Expect: Correct target type and method.
ast-grep --lang rust --pattern $'impl Deref for WrappedUserFeedItemHatsu {
  type Target = DbUserFeedItemHatsu;
  $$$
}'

Length of output: 581


13-15: Correctly defined UserFeedItemHatsu struct with appropriate fields.


17-38: Correctly implemented WrappedUserFeedItemHatsu with necessary traits and methods.


40-45: Ensure that into_db method correctly converts UserFeedItemHatsu to DbUserFeedItemHatsu.

Verification successful

The into_db method correctly converts UserFeedItemHatsu to DbUserFeedItemHatsu by transforming the about field from Option<Url> to Option<String> using to_string().

  • UserFeedItemHatsu has an about field of type Option<Url>.
  • DbUserFeedItemHatsu (aliased from hatsu_db_schema::user_feed_item::UserFeedItemHatsu) has an about field of type Option<String>.

The conversion logic in the into_db method is correct.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the `into_db` method implementation for `UserFeedItemHatsu`.

# Test: Search for the `into_db` method implementation. Expect: Correct conversion logic.
ast-grep --lang rust --pattern $'impl UserFeedItemHatsu {
  pub fn into_db(self) -> DbUserFeedItemHatsu {
    $$$
  }
}'

Length of output: 628



Script:

#!/bin/bash
# Description: Find and display the definition of `UserFeedItemHatsu`.

# Locate the definition of `UserFeedItemHatsu`.
ast-grep --lang rust --pattern 'struct UserFeedItemHatsu { $$$ }'

# Locate the definition of `DbUserFeedItemHatsu`.
ast-grep --lang rust --pattern 'struct DbUserFeedItemHatsu { $$$ }'

Length of output: 137



Script:

#!/bin/bash
# Description: Find and display the definition of `UserFeedItemHatsu` and `DbUserFeedItemHatsu`.

# Locate the definition of `UserFeedItemHatsu`.
rg 'struct UserFeedItemHatsu' -A 10

# Locate the definition of `DbUserFeedItemHatsu`.
rg 'struct DbUserFeedItemHatsu' -A 10

Length of output: 1531



Script:

#!/bin/bash
# Description: Find and display the definition of `DbUserFeedItemHatsu` and check for aliases or re-exports.

# Locate the definition of `DbUserFeedItemHatsu`.
rg 'DbUserFeedItemHatsu' -A 10

# Check for any aliases or re-exports of `DbUserFeedItemHatsu`.
rg 'type DbUserFeedItemHatsu' -A 10

Length of output: 2736

crates/db_schema/src/user_feed_item.rs (3)

3-4: Correctly added necessary imports for UserFeedItemHatsu.


19-20: Correctly added hatsu field to UserFeedItem struct.


22-24: Correctly defined UserFeedItemHatsu struct with appropriate fields.

crates/db_migration/src/m20240515_000001_user_feed_hatsu_extension.rs (3)

1-2: Correctly added necessary imports for the migration.


10-39: Correctly implemented up method to add and remove columns.


41-70: Correctly implemented down method to revert the changes.

crates/db_migration/src/m20240131_000002_user_feed_item.rs (3)

Line range hint 7-19: The up method for creating the UserFeedItem table looks correct.


Line range hint 21-27: The down method for dropping the UserFeedItem table looks correct.


Line range hint 45-81: The UserFeedItem enum defining the columns for the UserFeedItem table looks correct.

crates/db_schema/src/user.rs (4)

Line range hint 3-23: The Model struct defining the User entity with the new hatsu and feed fields looks correct.


27-32: The UserFeed struct defining the UserFeed entity looks correct.


34-38: The UserHatsu struct defining the UserHatsu entity looks correct.


Line range hint 39-49: The Relation enum and related implementations defining the relations for the User entity look correct.

crates/db_migration/src/m20240515_000002_user_feed.rs (2)

10-45: The up method for altering the User table looks correct.


50-85: The down method for altering the User table looks correct.

crates/db_migration/src/m20240131_000001_user.rs (3)

Line range hint 7-19: The up method for creating the User table looks correct.


Line range hint 21-27: The down method for dropping the User table looks correct.


Line range hint 51-81: The User enum defining the columns for the User table looks correct.

crates/feed/src/user_feed_top_level.rs (5)

8-27: The UserFeedTopLevel struct defining the fields for a JSON feed looks correct.


29-42: The get method for retrieving a JSON feed looks correct.


44-59: The get_full method for retrieving the full JSON feed looks correct.


61-63: The parse_json_feed method for parsing a JSON feed looks correct.


65-92: The parse_xml_feed method for parsing an XML feed looks correct.

crates/apub/src/actors/db_user_impl.rs (2)

Line range hint 23-51: The new method for creating a new ApubUser instance looks correct.


Line range hint 53-91: The send_activity method for sending an activity looks correct.

crates/feed/src/user_feed.rs (5)

11-18: The UserFeed struct defining the fields for a user feed looks correct.


21-42: The WrappedUserFeed struct wrapping the DbUserFeed struct looks correct.


44-51: The into_db method for converting a UserFeed instance into a DbUserFeed instance looks correct.


58-92: The get method for retrieving a user feed looks correct.


94-109: The get_top_level method for retrieving the top-level user feed looks correct.

crates/apub/src/actors/db_user.rs (2)

93-94: Ensure the new fields hatsu and feed are correctly initialized.

The new fields hatsu and feed are initialized to None. Verify that these fields are correctly handled in the rest of the codebase, especially during database operations and JSON conversions.


124-128: Ensure the hatsu field is correctly converted to JSON.

The hatsu field is converted to JSON by mapping its banner_image to a ServiceImage. Verify that this conversion logic is correct and that the hatsu field is properly handled in the rest of the codebase.

Copy link

@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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1da03e9 and dcbab41.
Files selected for processing (5)
  • crates/apub/src/actors/db_user_impl.rs (3 hunks)
  • crates/db_migration/src/m20240131_000002_user_feed_item.rs (1 hunks)
  • crates/feed/src/lib.rs (1 hunks)
  • crates/feed/src/user_feed_hatsu.rs (1 hunks)
  • crates/scheduler/src/update/job.rs (3 hunks)
Files skipped from review as they are similar to previous changes (5)
  • crates/apub/src/actors/db_user_impl.rs
  • crates/db_migration/src/m20240131_000002_user_feed_item.rs
  • crates/feed/src/lib.rs
  • crates/feed/src/user_feed_hatsu.rs
  • crates/scheduler/src/update/job.rs

@kwaa kwaa changed the title refactor(feed): improve structure refactor(feed)!: improve structure May 14, 2024
@kwaa kwaa merged commit ec17ccd into main May 14, 2024
1 check passed
@kwaa kwaa deleted the feat/feed branch May 14, 2024 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant