-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
WalkthroughThe recent changes streamline the Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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 ofUserFeedTopLevel
for parsing RSS feeds.
7-7
: Ensure thatparse_xml_feed
correctly handles the provided URL.Verification successful
The
parse_xml_feed
method inUserFeedTopLevel
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 ofUserFeedTopLevel
for parsing JSON feeds.
7-7
: Ensure thatparse_json_feed
correctly handles the provided URL.Verification successful
parse_json_feed
correctly handles the provided URLThe
parse_json_feed
method inUserFeedTopLevel
correctly handles the provided URL by usingreqwest::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 doneLength of output: 571
crates/feed/src/lib.rs (3)
2-3
: Correctly added new modulesuser_feed_top_level
anduser_feed_hatsu
.
7-9
: Correctly updated public exports to include new structs.
11-11
: Ensure thatUserFeedItemHatsu
is correctly implemented and used.Verification successful
The
UserFeedItemHatsu
struct is implemented in two different files with different field types (Url
incrates/feed/src/user_feed_item_hatsu.rs
andString
incrates/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
: UsesUrl
and provides a method to convert it toString
.crates/db_schema/src/user_feed_item.rs
: UsesString
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.rsLength 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 5Length of output: 5862
crates/db_migration/src/lib.rs (2)
10-11
: Correctly added new migration modulesm20240515_000001_user_feed_hatsu_extension
andm20240515_000002_user_feed
.
26-27
: Correctly included new migrations in theMigrator
implementation.crates/feed/src/user_feed_hatsu.rs (4)
1-2
: Ensure that theDeref
trait implementation is correct.Verification successful
The
Deref
trait implementation forWrappedUserHatsu
is correctly targetingDbUserHatsu
and thederef
method is properly implemented.
type Target = DbUserHatsu;
is correctly specified.- The
deref
method returns a reference toself.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 definedUserFeedHatsu
struct with appropriate fields.
18-39
: Correctly implementedWrappedUserHatsu
with necessary traits and methods.
41-48
: Ensure thatinto_db
method correctly convertsUserFeedHatsu
toDbUserHatsu
.Verification successful
The
into_db
method correctly convertsUserFeedHatsu
toDbUserHatsu
by transforming theabout
andbanner_image
fields fromOption<Url>
toOption<String>
.
UserFeedHatsu
definition:pub struct UserFeedHatsu { pub about: Option<Url>, pub banner_image: Option<Url>, }
DbUserHatsu
(aliasUserHatsu
) 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 rustLength 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 rustLength 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.rsLength of output: 355
crates/feed/src/user_feed_item_hatsu.rs (4)
1-2
: Ensure that theDeref
trait implementation is correct.Verification successful
The
Deref
trait implementation forWrappedUserFeedItemHatsu
is correctly defined incrates/feed/src/user_feed_item_hatsu.rs
at lines 26-32. TheTarget
type is set toDbUserFeedItemHatsu
, and thederef
method returns a reference toself.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 definedUserFeedItemHatsu
struct with appropriate fields.
17-38
: Correctly implementedWrappedUserFeedItemHatsu
with necessary traits and methods.
40-45
: Ensure thatinto_db
method correctly convertsUserFeedItemHatsu
toDbUserFeedItemHatsu
.Verification successful
The
into_db
method correctly convertsUserFeedItemHatsu
toDbUserFeedItemHatsu
by transforming theabout
field fromOption<Url>
toOption<String>
usingto_string()
.
UserFeedItemHatsu
has anabout
field of typeOption<Url>
.DbUserFeedItemHatsu
(aliased fromhatsu_db_schema::user_feed_item::UserFeedItemHatsu
) has anabout
field of typeOption<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 10Length 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 10Length of output: 2736
crates/db_schema/src/user_feed_item.rs (3)
3-4
: Correctly added necessary imports forUserFeedItemHatsu
.
19-20
: Correctly addedhatsu
field toUserFeedItem
struct.
22-24
: Correctly definedUserFeedItemHatsu
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 implementedup
method to add and remove columns.
41-70
: Correctly implementeddown
method to revert the changes.crates/db_migration/src/m20240131_000002_user_feed_item.rs (3)
Line range hint
7-19
: Theup
method for creating theUserFeedItem
table looks correct.
Line range hint
21-27
: Thedown
method for dropping theUserFeedItem
table looks correct.
Line range hint
45-81
: TheUserFeedItem
enum defining the columns for theUserFeedItem
table looks correct.crates/db_schema/src/user.rs (4)
Line range hint
3-23
: TheModel
struct defining theUser
entity with the newhatsu
andfeed
fields looks correct.
27-32
: TheUserFeed
struct defining theUserFeed
entity looks correct.
34-38
: TheUserHatsu
struct defining theUserHatsu
entity looks correct.
Line range hint
39-49
: TheRelation
enum and related implementations defining the relations for theUser
entity look correct.crates/db_migration/src/m20240515_000002_user_feed.rs (2)
10-45
: Theup
method for altering theUser
table looks correct.
50-85
: Thedown
method for altering theUser
table looks correct.crates/db_migration/src/m20240131_000001_user.rs (3)
Line range hint
7-19
: Theup
method for creating theUser
table looks correct.
Line range hint
21-27
: Thedown
method for dropping theUser
table looks correct.
Line range hint
51-81
: TheUser
enum defining the columns for theUser
table looks correct.crates/feed/src/user_feed_top_level.rs (5)
8-27
: TheUserFeedTopLevel
struct defining the fields for a JSON feed looks correct.
29-42
: Theget
method for retrieving a JSON feed looks correct.
44-59
: Theget_full
method for retrieving the full JSON feed looks correct.
61-63
: Theparse_json_feed
method for parsing a JSON feed looks correct.
65-92
: Theparse_xml_feed
method for parsing an XML feed looks correct.crates/apub/src/actors/db_user_impl.rs (2)
Line range hint
23-51
: Thenew
method for creating a newApubUser
instance looks correct.
Line range hint
53-91
: Thesend_activity
method for sending an activity looks correct.crates/feed/src/user_feed.rs (5)
11-18
: TheUserFeed
struct defining the fields for a user feed looks correct.
21-42
: TheWrappedUserFeed
struct wrapping theDbUserFeed
struct looks correct.
44-51
: Theinto_db
method for converting aUserFeed
instance into aDbUserFeed
instance looks correct.
58-92
: Theget
method for retrieving a user feed looks correct.
94-109
: Theget_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 fieldshatsu
andfeed
are correctly initialized.The new fields
hatsu
andfeed
are initialized toNone
. Verify that these fields are correctly handled in the rest of the codebase, especially during database operations and JSON conversions.
124-128
: Ensure thehatsu
field is correctly converted to JSON.The
hatsu
field is converted to JSON by mapping itsbanner_image
to aServiceImage
. Verify that this conversion logic is correct and that thehatsu
field is properly handled in the rest of the codebase.
There was a problem hiding this 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
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
Summary by CodeRabbit
New Features
hatsu
andfeed
for user feeds.UserFeedHatsu
andUserFeedItemHatsu
for JSON Feed extensions.Bug Fixes
Refactor
feed_json
,feed_atom
, andfeed_rss
fields withhatsu
andfeed
.UserFeed
toUserFeedTopLevel
for better clarity.Tests
UserFeed
toUserFeedTopLevel
.Chores