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

Bug 1884816 - Expose icon information for suggestion as struct #6162

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dadaa
Copy link
Contributor

@dadaa dadaa commented Mar 12, 2024

https://bugzilla.mozilla.org/show_bug.cgi?id=1884816

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due dilligence applied in selecting them.

Branch builds: add [firefox-android: branch-name] to the PR title.

@dadaa dadaa requested review from 0c0w3 and linabutler March 12, 2024 03:03
@codecov-commenter
Copy link

codecov-commenter commented Mar 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.09%. Comparing base (ffacc52) to head (2ed4964).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6162   +/-   ##
=======================================
  Coverage   84.09%   84.09%           
=======================================
  Files         117      117           
  Lines       15627    15627           
=======================================
  Hits        13141    13141           
  Misses       2486     2486           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@0c0w3 0c0w3 left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

Naming nit: Can we use data instead of content everywhere please? data is more natural, it matches the column name in the DB, and it's shorter.

Smaller naming nit: It would be nice to consistently use mimetype or mime_type, but no big deal I guess. It's two words, but I don't think we should change the DB schema just for that. I wonder if there's a Rust convention for one over the other?

Comment on lines 309 to 315
let icon = match row.get("icon_content")? {
Some(content) => Some(SuggestionIcon {
content,
mime_type: row.get("icon_mimetype")?,
}),
_ => None,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I would write this using Option::map(), but I'm not sure it's better and Lina might disagree:

                        let icon_content = row.get::<_, Option<_>>("icon_content")?;
                        let icon_mimetype = row.get::<_, Option<_>>("icon_mimetype")?;
                        let icon = icon_content.map(|content| SuggestionIcon {
                            content,
                            mime_type: icon_mimetype.unwrap_or_else(|| "".into()),
                        });

Comment on lines 242 to 247
Ok(match result {
(Some(content), Some(mime_type), score) => {
(Some(SuggestionIcon { content, mime_type }), score)
}
_ => (None, result.2),
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to above, I would use map():

        let (icon_content, icon_mimetype, score) = self.conn.query_row_and_then_cachable(
            // ...
        )?;
        let icon = icon_content.map(|content| SuggestionIcon {
            content,
            mime_type: icon_mimetype.unwrap_or_else(|| "".into()),
        });
        Ok((icon, score))

@dadaa
Copy link
Contributor Author

dadaa commented Mar 12, 2024

Thank you very much, @0c0w3 !

Naming nit: Can we use data instead of content everywhere please? data is more natural, it matches the column name in the DB, and it's shorter.

Okay!

Smaller naming nit: It would be nice to consistently use mimetype or mime_type, but no big deal I guess. It's two words, but I don't think we should change the DB schema just for that. I wonder if there's a Rust convention for one over the other?

Yeah, I also thought about the name consistency.. So, I will use mimetype for now to match with the DB scheme. Then, if we want to rename, will do it in another PR.

Copy link
Member

@linabutler linabutler left a comment

Choose a reason for hiding this comment

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

This looks wonderful, thank you @dadaa! I had a small preference for mime_type over mimetype, but don't feel strongly about it—please feel free to keep mimetype if you prefer.

We're going to need breaking change PRs on Android (and tests) and iOS, though. I added a section to the readme about them, but I'd be happy to walk you through the process!

Please make sure to also add a CHANGELOG.md entry for this breaking change. (You might need to add a "Breaking Changes" section for v125.0; check out this example).

#[derive(Clone, Debug, PartialEq)]
pub struct SuggestionIcon {
pub data: Vec<u8>,
pub mimetype: String,
Copy link
Member

Choose a reason for hiding this comment

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

Hah, I was just about to suggest mime_type, and then saw you renamed it for consistency with the schema.

I think mime_type looks a little cleaner (it becomes mimeType in JS, Swift, and Kotlin; mimetype there almost looks like a typo). I wouldn't worry too much about keeping it consistent with the schema—we already have other fields that use different names! ☺️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay! I will change to mime_type.

let icon_mimetype = row.get::<_, Option<_>>("icon_mimetype")?;
let icon = icon_data.map(|data| SuggestionIcon {
data,
mimetype: icon_mimetype.unwrap_or_else(|| "".into()),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
mimetype: icon_mimetype.unwrap_or_else(|| "".into()),
mimetype: icon_mimetype.unwrap_or_default(),

I think this should work; please ignore if it doesn't!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! This works!

@dadaa
Copy link
Contributor Author

dadaa commented Mar 18, 2024

We're going to need breaking change PRs on Android (and tests) and iOS, though. I added a section to the readme about them, but I'd be happy to walk you through the process!

@linabutler
I want to confirm what to do.

  1. Create a branch (e.g. application-service-pr6162) on Android side that adapts to this change.
  2. Push the branch as PR to firefox-android
  3. Push this PR with title including [firefox-android: application-service-pr6162]
  4. Create a branch (e.g. application-service-pr6162) on iOS side that adapts to this change.
  5. Push the branch as PR to firefox-ios
  6. If 3 is no problem, merge this.
  7. Merge iOS PR

Am I right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants